Hello
I have document with nested documents:
{ "_id": 111 "price": 1000 "properties": [ { "property_id": 22, "property_value": "gas"} { "property_id": 23, "property_value": "green"} ] }
I have a request that gives me the expected score by the price (from 1 to 100).
I need to add a +30 score if the nested document has a param_id == 23 AND param_value == "red". However, if the document doesn't have this nested document, then still return the document, just without these +30 score (can't just add filter that will delete the result without specific value)
I try:
{ "query": { "nested": { "path": "properties", "query": { "function_score": { "query": { "bool": { // search specific nested document "filter": [ { "term": { "properties.property_id": 23 } }, { "term": { "properties.property_value": "red" } } ] } }, "script_score": { "script": { "source": "30" // if find nested document, then add 30 score } } } } } } }, "sort": { "_score": { "order": "desc" } } }
result: search_phase_execution_exception
I try:
{ "query": { "bool": { "must": [ [ { "nested": { "path": "properties", "query": [ { "function_score": { "functions": [ { "weight": 30 // if find nested document, then add 30 score "filter": [ // search specific nested document { "term": { "properties.property_id": 23 } }, { "term": { "properties.property_value": "red" } } ] } ] } } ] } } ] ] } }, "sort": { "_score": { "order": "desc" } } }
result: [_na] query malformed, must start with start_object
I try:
{ "query": { "bool": { "must": [ [ { "nested": { "path": "properties", "query": [ { "constant_score": { "filter": [ // search specific nested document { "term": { "properties.property_id": 23 } }, { "term": { "properties.property_value": "red" } } ], "boost": 30 // if find nested document, then add 30 score } } ] } } ] ] } }, "sort": { "_score": { "order": "desc" } } }
result: return document where has property_id == 23 AND property_value == "red", but add 1 score, and no dependence on boost