Return a result from every index when searching multiple indices


(philipDS) #1

Hey!

I have 4 indices with different types in them (and thus different mappings). Now, I want to execute a query and get at least 1 document from every index (if ES finds one related to the query). Is this possible?

Currently, I'm doing this:

return this.getClient().prepareSearch("W", "X", "Y", "Z")
.setTypes("A", "B", "C", "D", "E", "F")
.addIndexBoost("W", (float)1.4)
.addIndexBoost("X", (float)1.1)
.setFrom(q.getFrom())
.setRouting(q.getUser())
.setSize(MAX_HITS).setExplain(q.getExplain())
.addSort(sort, SortOrder.DESC)
.setFilter(q.getBody());

I also tried playing around with boosting a little bit, but this doesn't give me the results I needed. Is it somehow possible to say to ES: distribute your results over W, X, Y, Z and get at least 5 results from every index, while doing only one search?


(system) #2