Search within differnt indices get same amount of documents

(Super Yang) #1

I want to got the same amount of documents from different indices within one query
For Examples:
two indices Company / Person, both have a field called "name"
And I want to search all name match "smart", but I want got the same amount from Company and Person
I want get the result like this [ company1, company2, ..., Company5] AND [Person1, Person2, ..., Person5], as you see, 10Results with 5 Companys and 5 Persons
Besides, I'm using es5.3

So Anyone have some ideas?

(David Pilato) #2

You can use the multisearch API and set the size for both queries to 5 may be?

(Super Yang) #3

3x I'll have a try

(Super Yang) #4

@dadoonet thanks for your kind
I finally got the right result, my code like this

GET test-1/_msearch
{"index" : "company"}
{"query" : {"match_all" : {}},"size":3}
{"index" : "person"}
{"query" : {"match_all" : {}},"size":3}