I'm pretty new in elasticsearch and I need help to compose search query.
I have index type under name "modelresult" wich contains a few indexed DB tables. The mapping http://pastebin.com/G0AeXDFB
I need to filter all ads (docs with django_ct eq to "ads.ad") with condition:
(category1: filter1 OR filter2 OR filter3) AND (category2: filter4 OR filter5 OR filter6) AND (categoryN: OR ) AND (etc)
Where is category noted with fields - filters_ids, filters_names, filters_slugs
and filter is - filters_ids, filters_names, filters_slugs
(Ad can contain a multiple filters and hence a multiple categories)
Currently I'm using this query , but it's not I wanted.
Currently I use this query http://pastebin.com/W6EHeJmx, but that's not what I need.
If we parse your top level expression which is
(..) AND (..) AND (..) this can be represented as a
bool query with a
must array to hold the subclauses. Each of your subclauses is a list of alternative values for the same field so you can use the
terms query to list them succinctly. This gives us the following:
"category1": ["filter1", "filter2", "filter3"]
"category2": ["filter4", "filter5", "filter6"]
This will work but we can improve on it because there are sections of this query we may not want to contribute to scoring results - it will take longer to compute and if we turn it into a
filter expression Elasticsearch can agressively cache its results as yes/no bits it can reuse in similar queries. To do this we can wrap the
terms clauses under a
bool>filter arrangement. See here for more: Combining Filters | Elasticsearch: The Definitive Guide [2.x] | Elastic
Hi. Thanks for the answer. Unfortunately I made a critical error in the question. The bottom line is that the categories to which belongs ad indicates a set of fields: filters_categories_ids, filters_categories_names and filters_categories_slugs. Thus, this answer does not fit as the index does not store a collection of categoryN fields.
I suggest you supply an example doc as JSON and your intended query written as pseudocode
Thanks for taking time. Here is real document. Note - text data is mainly in russian.
Here is how I think it should work:
var1 = [category1, category2]
var2 = [filter1, filter2]
for doc in docs
if var1 is a subset of doc.filter_categories_ids
if any of var2 in doc.filters_ids
P.S. sorry for my english.