Execute Multiple Search Query in Elasticsearch

Execute Multiple Search Query in Elasticsearch

Execute Multiple Search Query in Elasticsearch

           The following query can be used to execute multiple search queries on the required index and type. Elasticsearch will process the request and the response is sent as array field named responses which contains the response for each query. 

Note :

  • { “index”: “INDEX_NAME_1”, “type”: “TYPE_NAME_1” } in Example 1 should not span multiple lines
  • { “query”: { “match_all”: {}}} in the Example 1 is the query and make sure this line also doesn’t span multiple lines
  • The first line (POST /_msearch) represents type of query
  • The following two lines will represent a search query.
  • Add any number of query based on your requirement

Example 1:

POST /_msearch
{ "index": "INDEX_NAME_1", "type": "TYPE_NAME_1" }
{ "query": { "match_all": {}}}
{ "index": "INDEX_NAME_2", "type": "TYPE_NAME_2" }
{ "query": { "match_all": {}}}

Sample Response for Example 1 :

{
   "responses": [
      {
         "took": 4700,
         "timed_out": false,
         "_shards": {
            "total": 1060,
            "successful": 1060,
            "failed": 0
         },
         "hits": {
            "total": 24855713,
            "max_score": 1,
            "hits": [......]
         }
      },
      {
         "took": 4629,
         "timed_out": false,
         "_shards": {
            "total": 1060,
            "successful": 1060,
            "failed": 0
         },
         "hits": {
            "total": 520958748,
            "max_score": 1,
            "hits": [......]
         }
      }
   ]
}

Example 2:

POST /_msearch
{ "index": "INDEX_NAME", "type": "TYPE_NAME" }
{ "query": { "match_all": {}}}

Sample Response for Example 2 :

{
   "responses": [
      {
         "took": 4700,
         "timed_out": false,
         "_shards": {
            "total": 1060,
            "successful": 1060,
            "failed": 0
         },
         "hits": {
            "total": 24855713,
            "max_score": 1,
            "hits": [......]
         }
      }
   ]
}

Related Links: 

Web Application for Elasticsearch :
  1. ElasticTab – Elasticsearch to Excel Report (Web Application)
Elasticsearch Plugin:
  1. Elasticsearch Plugin To Generate (Save and E-Mail) Excel Reports
Elasticsearch:
  1. Execute Multiple Search Query in Elasticsearch
  2. Monitor Elasticsearch Servers with Shell Script - E-Mail Notification
  3. Execute Raw Elasticsearch Query using Transport Client – Java API
  4. Elasticsearch – Apply Nested Filter on Nested (Inner) Aggregation
  5. Execute Multiple Search Query in Elasticsearch
  6. Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX
  7. Elasticsearch Java API – Get Index List
  8. Elasticsearch Java API – Get Alias List
  9. Elasticsearch Java API - Get Type List from given Index
  10. Elasticsearch Java API – Get Field List for a given Index and Type
  11. Elasticsearch Java API – Get Index Type List Mapping
  12. Elasticsearch – Use Script Filter/Conditon in Aggregation/Sub-Aggreagtion
  13. Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API
  14. Elasticsearch - Date/Time(String)  Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds
Logstash:
  1. Logstash – Process Log File Once and Exit/Stop Logstash After Reading Log File Once
  2. Measure Logstash Performance using Metrics Filter – Issue/Error in Syntax (Unknown setting ‘message’ for stdout)
  3. Logstash – Process Same Log File (File Input) from Beginning/Start
  4. Create Custom Filter/Plugin to Emit New Events Manually in Logstash
Logstash and Elasticsearch:
  1. Query Elasticsearch Cluster in Filter Section when using Logstash
  2. Custom Elasticsearch Index Name/Type Name based on Events in Logstash
MongoDB and Elasticsearch:
  1. Import Data from Mongo DB to Elasticsearch using Elasticsearch River
 Read More...

[ YOU MAY ALSO LIKE ]

Leave a Reply