Having trouble converting a filtered query into a bool query for Elasticsearch 5 -
i'm in process of upgrading elasticsearch 1.7 5.0. 1 of changes removal of filtered query in favor of bool query. example, have search hash being used in older version of es:
{ "sort": [ { "updated_at" => "desc" } ], "query": { "filtered": { "filter": { "bool": { "must": [ { "term": { "account_id" => 2 } }, { "bool": { "should": [ { "missing": { "field": "workgroup_ids" } }, { "term": { "visibility": 2 } } ] } } ], "must_not": [ { "range": { "expires_at": { "lte": "2016-11-17t16:27:22z" } } }, { "range": { "published_at": { "gte": "2016-11-17t16:27:22z" } } } ] } }, "query": { "bool": { "must": [ { "query_string": { "query": "name:(*orang.jpg*)" } } ] } } } }}
so, know needs more in format of:
{ "query": "bool": [{ term: { account_id: 2 } }]}
i know missing query needs replaced must_not exists query in 5. said, i'm having trouble figuring out how convert heavily nested hash know how structure correctly es5?
i'm using/accessing es in rails utilizing elasticsearch-rails gem, fyi.
i think can change , should work:
{ "sort": [ { "updated_at": "desc" } ], "query": { "bool": { "must": [ { "query_string": { "query": "name:(*orang.jpg*)" } } ], "must_not": [ { "range": { "expires_at": { "lte": "2016-11-17t16:27:22z" } } }, { "range": { "published_at": { "gte": "2016-11-17t16:27:22z" } } } ], "filter": [ { "bool": { "minimum_should_match": 1, "should": [ { "bool": { "must_not": { "exists": { "field": "workgroup_ids" } } } }, { "term": { "visibility": 2 } } ] } }, { "term": { "account_id": 2 } } ] } } }
Comments
Post a Comment