Search code examples
solrelasticsearchlucenespring-data-elasticsearchfederated

Out of the box federated search using Lucene/Solr/ElasticSearch


I have a requirement in which I want to search two or more search index when a particular query is being submitted to search server. Is there a way in which I can collectively search two or more search indexes (all of them indexes different things about the same entity being searched for) and get a single set of responses (response from two or more search indexes) when using Lucene/Solr/Elasticsearch? If this is not possible I am trying to set up something on the API level where the search indexes are abstracted away from the search clients where the query is submitted to the API & the API under the hood launces searches in parallel to two or more search indexes and combines the results and sends it back?

The point here is that I don't want to reinvent the wheel if there is such an API framework is available or even if its possible using Lucene/Solr/Elasticsearch out of the box or by simply installing a plugin & configuring it?


Solution

  • You can easily do this using elasticsearch. While searching you can mention the indices names in a comma separated format like below -

    curl -XPOST 'http://localhost:9200/index-a,index-b,index-c/_search -d '{
      "query": {
        "match_all": {}
      }
    }'
    

    For convenience sake , you can also use aliases. Alias can bind to multiple index names and you can use a single alias to talk to all those indices