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:

  1. add index mapping
put /staff {     "mappings": {         "staff": {             "properties": {                 "id": {                     "type":   "string",                     "index":  "not_analyzed"                 },                 "name": {                      "type":     "string",                     "fields": {                         "raw": {                              "type":  "string",                             "index": "not_analyzed"                         }                     }                 }             }         }     } } 
  1. add document
post /staff/list {         "id": 5,         "name": "abc"      } 
  1. 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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -