I was wondering if there was a way to do one call with multiple indexes but also have individual queries for each index?
Currently i am specifying all of my indexes that i need above the body > index:[index1, index2, etc]
Then in the query i am using lots of bools with must not field exists (if field exists then do this query), this seems to work but is getting complicated as my index list increases.
I realize i could just do separate calls for each index (with their own queries) but this way is alot faster and i also realize that these indexes should be normalized (but they are not and i have no control over that).
To sum it up i am trying to allow users to select some options and an optional search string, let the system search across all of the specified indexes for these options (if they make sense for that index - e.g. some have product fields some dont) and then bring back the match count for each index (the count part i am using aggs on the _type field).
You could do this in one query by building a composite query that combines the query that you would wish to execute against a specific index with a term or terms query that filters only to those indices you're interested in.
As an example, here's a query that executes a search request against all indices, but targets indices index-1 and index-2 differently to the rest by using two bool queries in the should clause of a bool query. Each of the inner bool queries combines a must clause (the query to execute) with a filter or must_not clause that determines the indices to apply to.
Any reason why we need to negate the fields and not promote them? Just want to understand why its working rather than "it works". In my head i would want to think " i want to match these fields to these indexes" but the way this works is "i want to match these fields to any index apart from these.
This is purely an example; you can extend the number of bool queries as should clauses to implement pretty much any arbitrary index targeting that you need to perform.
I pulled this example out of another question that was asking how to support similar functionality to indices queries now that they're deprecated in 5.x
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.