ElasticSearch Script Score Using Field Value -
ElasticSearch Script Score Using Field Value -
elasticsearch 1.2.1
i trying query documents using weighted tags.
curl -x  set 'http://localhost:9200/test'  curl -x  set 'http://localhost:9200/test/thing/_mapping' - '{     "thing": {         "properties": {             "tags": {                 "type": "nested",                 "properties": {                         "name": { "type": "string" },                         "weight": { "type": "integer" }                 }             }         }     }}'    adding document:
curl -x  set 'http://localhost:9200/test/thing/1', -d '{     "tags": [         { "name": "a", "weight": 2 }     ] }'    now searching documents having tag a , boost score based on weight.
note: run these examples have enable dynamic scripting in elasticsearch:  add together script.disable_dynamic: false elasticsearch.yml
curl -x 'http://localhost:9200/test/thing/_search?pretty' -d '{     "query": {         "function_score": {           "boost_mode": "replace",           "query": {             "match_all": {}           },           "functions": [             {               "filter": {                 "nested": {                   "path": "tags",                   "filter": {                     "term": {                       "tags.name": "a"                     }                   }                 }               },               "script_score": {                 "script": "doc.weight.value"               }             }           ]         }     } }'    the document found, expected, score 0. seems if property doc.weight empty.
let's test replacing script doc.weight.empty ? 50 : 100.   nail has score of 50 indicating field doc.weight empty. found though, because using non-existant field name (e.g. doc.foobar) gives error.
background: match_all part replaced real query. want  utilize tags boost results matching tags before ones not matching tags.
what missing?
 elasticsearch 
 
Comments
Post a Comment