sql - Elasticsearch match combos of two fields -
how can simple sql query running on elasticsearch?
select * [mytype] (id=123 , cid = classroomida) or (id=234 , cid = classroomidb) or (id=345 , cid = classroomidc)
i'm having troubles syntax, multi-match queries doesn't work in case. type of query should use?
the right way combine bool/should
(for outer or conditions) , bool/filter
(for inner , conditions) together.
post mytype/_search { "query": { "bool": { "minimum_should_match": 1, "should": [ { "bool": { "filter": [ { "term": { "id": 123 } }, { "term": { "cid": "classroomida" } } ] } }, { "bool": { "filter": [ { "term": { "id": 234 } }, { "term": { "cid": "classroomidb" } } ] } }, { "bool": { "filter": [ { "term": { "id": 345 } }, { "term": { "cid": "classroomidc" } } ] } } ] } } }
update
the equivalent es 1.7 query (just replace bool/filter
bool/must
):
post mytype/_search { "query": { "bool": { "minimum_should_match": 1, "should": [ { "bool": { "must": [ { "term": { "id": 123 } }, { "term": { "cid": "classroomida" } } ] } }, { "bool": { "must": [ { "term": { "id": 234 } }, { "term": { "cid": "classroomidb" } } ] } }, { "bool": { "must": [ { "term": { "id": 345 } }, { "term": { "cid": "classroomidc" } } ] } } ] } } }
Comments
Post a Comment