javascript - Elasticsearch: Matching documents with an array in it -
i'm new elasticsearch , documentation confuses me please bear me little bit here.
i have index called zproducts , under type called item mapped looks this:
{ "item_name" : "product a", "category_ids" : [ "id1", "id2" ] }, { "item_name" : "product b", "category_ids" : [ "id1" ] }, { "item_name" : "product c", "category_ids" : [ "id2" ] } i want able query items match @ least 1 of of categories. ie. querying id2 return products , c.
it seem have exact same problem this guy had.
but solution suggested there doesn't work me.
this current query:
/zproducts/items/_search
{ "query": { "bool": { "must": [ { "term": { "category_ids": "id2" } } ] } } } subsequent test query:
{ "query": { "filtered": { "filter": { "term": { "category_ids": "id2" } } } } } both queries return items on store , not ones i'm trying query for.
there original query which, reason, used work stopped working altogether.
{ "query": { "bool": { "must": [ { "match": { "category_ids": { "query": "id2", "operator": "or" } } } ] } } } so doing wrong here? can please shed light?
this query:
{ "query": { "filtered": { "filter": { "term": { "category_ids": "id2" } } } } } is correct. make sure making request post /zproducts/items/_search, rather get /zproducts/items/_search - getting documents in index query hint query body being ignored, hint you're using get; many clients not send request body request, es interprets blank query.
Comments
Post a Comment