elasticsearch sorting unexpected null returned -
i followed doc https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html add sorting column name field. unfortunately, not working
these steps:
- add index mapping
put /staff { "mappings": { "staff": { "properties": { "id": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } }
- add document
post /staff/list { "id": 5, "name": "abc" }
- search name.raw
post /staff_change/_search { "sort": "name.raw" }
however, sort field in response return null
"_source": { "id": 5, "name": "abc" }, "sort": [ null ] }
i dont know why not working , cant search relevant issue doc related this. come across issue
many in advance
your mappings incorrect. create mapping staff
inside index staff
, index documents under mapping list
inside index staff
works dynamic mapping, not 1 added. in end searching documents in index staff
. try this:
put /staff { "mappings": { "list": { "properties": { "id": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } }
then index:
post /staff/list { "id": 5, "name": "abc aa" }
and query:
post /staff/list/_search { "sort": "name.raw" }
results in:
"hits": [ { "sort": [ "abc aa" ] } ...
Comments
Post a Comment