Closed eubinecto closed 4 years ago
There is JSONResponse object for that.
# import it
from django.http import JsonResponse
def my_view(request):
# do something with the your data
data = {}
# just return a JsonResponse
return JsonResponse(data)
location:
search
- queries.py
design paradigm:
File "/Users/eubin/Desktop/Projects/Big/youtora/ytrenv/lib/python3.8/site-packages/elasticsearch/connection/http_urllib3.py", line 269, in perform_request
self._raise_error(response.status, raw_data)
File "/Users/eubin/Desktop/Projects/Big/youtora/ytrenv/lib/python3.8/site-packages/elasticsearch/connection/base.py", line 300, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', "object mapping [caption] can't be changed from non-nested to nested")
init을 하지 않고 그냥 저장을 한다음에, 다시 init을 시도하면 위와 같은 에러가 뜬다.
이걸 어떻게 해결해야하나? Nested field라면 reference를 어떻게 해야하지?
curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
'
curl -X PUT "localhost:9200/my-index-000001/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
'
curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"nested": {
"path": "user",
"query": {
"bool": {
"must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "Smith" }}
]
}
}
}
}
}
'
curl -X GET "localhost:9200/my-index-000001/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"nested": {
"path": "user",
"query": {
"bool": {
"must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "White" }}
]
}
},
"inner_hits": {
"highlight": {
"fields": {
"user.first": {}
}
}
}
}
}
}
'
why?
to isolate frontend from backend logics.
how?
~get use of django api framework?~ just use django views for that.