Filter by id in array and return only item with id, Elasticsearch 1.7 -


how filter offers array id field , return in results object searched id?

current search correctly find data id in offers array returns objects it:

get activities/activity/_search {    "query": {       "filtered": {          "filter": {             "bool": {                "must": [                   {                     "term": {                       "offers.id": "12"                     }                   }                ]             }          }       }    } } 

current results, filter offers , "id": 12:

"hits": [    {       "_index": "activities",       "_type": "activity",       "_id": "avtr4-uv81wmr8kfd246",       "_score": null,       "_source": {          "offers": [             {                "title": "merge",                "id": 11             },             {                "title": "order test",                "id": 12             }          ],          "event": "candidate_remove",          "created_at": "2017-04-14t09:55:49.115174z"       }    } ] 

mapping offers in activity type:

"offers": {    "type": "nested",    "include_in_parent": true,    "properties": {       "id": {          "type": "long"       },       "title": {          "type": "string",          "index": "not_analyzed"       }    } }, 

you need inner_hits functionality , nested query:

{   "query": {     "filtered": {       "filter": {         "bool": {           "must": [             {               "nested": {                 "path": "offers",                 "query": {                   "term": {                     "offers.id": "12"                   }                 },                 "inner_hits":{}               }             }           ]         }       }     }   } } 

this add section in response called inner_hits it's showing matching nested documents.

if don't need original offers value, add original query:

{   "_source": {"exclude": "offers"},    "query": {     "filtered": { 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -