Home > Blockchain >  ElasticSearch: how to search from multiple indexes
ElasticSearch: how to search from multiple indexes

Time:09-08

I have a situation where I need to search from multiple indexes (products and users). Below is a sample query I am using to do that search

http://localhost:9200/_all/_search?q=*wood*
http://localhost:9200/users,products/_search?q=*wood*

With the above API request, it only returns search results for the product index. But if I search using the below API it returns search results for users index

http://localhost:9200/users/_search?q=*wood*

As you can see I am passing same value for "q" parameter. I need to search for both product and users index and check if there is the word "wood" in any attribute in both indexes. How can I achieve this

CodePudding user response:

You can pass multiple index names instead of _all as it will search in other indices that you don't intent to by using the comma seprated index name like

http://localhost:9200/users,products/_search?q=*wood*

Although, _all should also fetch the result from users index which you get when you specify its name, you need to debug why its happening, maybe increase the size param to 1000 as by default Elasticsearch returns only 10 results and it seems in case of _all all the top results coming from products index only.

  • Related