Can I fire multiple queries together and get results as different data sets for particular query?

Is there a way to fire multiple queries together and get results for each query differently?

Means, suppose I have 3 mobile numbers, and I want to query each mobile number and store its data against that mobile number at once.

Currently when I do a query with 3 mobile numbers like below,

{
    "query": {
   "bool": {
   "should": [
     {"match": {"mobile_1":"9004000123","_name" : "first"}},
     {"match": {"mobile_1":"8308655111"}},
     {"match": {"mobile_1":"9137002511"}},
     {"match": {"mobile_1":"9999999999"}}
   ]
  }
 },
 "_source": ["padd","padd_pincode","ladd","ladd_pincode","fname","cname","fingerprint","dob","mobile_2","mobile_1","state"]
        }

It gives all the matching records but all together, I want response for each mobile number, so that I do not need to find records, matching a particular mobile number.
May be responses with a key for each mobile number, please let me know if any confusion.

{'name': 'e5b6b6dcf7010c1af2fdefb254f44d9e', 'cluster_name': '605340070629:spocto-test1', 'cluster_uuid': 'Q-h-DDEzT-yIjyxOlb181A', 'version': 
{'number': '7.1.1', 'build_flavor': 'oss', 'build_type': 'tar', 'build_hash': '0cae80c', 'build_date': '2019-08-20T18:17:04.430100Z', 'build_snapshot': False, 'lucene_version': '8.0.0', 'minimum_wire_compatibility_version': '6.8.0', 'minimum_index_compatibility_version': '6.0.0-beta1'}, 'tagline': 'You Know, for Search'}

{'took': 107, 'timed_out': False, '_shards': 

{'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0}, 

'hits': 
{'total': 
{'value': 5, 'relation': 'eq'}, 'max_score': 1.0, 'hits': [

{'_index': 'new_spb', '_type': '_doc', '_id': '37c8f7ab1197abb7f8855897e92eeb731968005723354ba61a4810e57d86f387', '_score': 1.0, '_source': {'ladd_pincode': 401506, 'fname': 'Upendra Chaudhary', 'padd': 'PLOT NO. J-85 VALIANT GLASS WORKS PVT LTD, NAVAPUR ROAD BOISAR, SALWAD TARAPUR TI, PALGHAR THANE-THANE MH 401506', 'dob': '1970-01-01', 'ladd': 'S/O: UPENDRA CHAUDHARY, PLOT NO. J-85 VALIANT GLASS WORKS PVT LTD NAVAPUR ROAD, BOISAR TARAPUR TI, PALGHAR SALWAD-THANE MH 401506', 'cname': 'Sanjaykumar Chaudhary', 'fingerprint': '37c8f7ab1197abb7f8855897e92eeb731968005723354ba61a4810e57d86f387', 'padd_pincode': 401506, 'state': 'Maharashtra', 'mobile_1': 8308655111, 'mobile_2': None}},

 {'_index': 'new_spb', '_type': '_doc', '_id': 'cee6bdca75c9aac1c7c3e06a17e5729b26ec31704a4bc7bdb32c4105e232da4c', '_score': 1.0, '_source': {'fname': 'Ramsagar', 'padd': ',MOHAMMADABAD GOHNASURHURPUR,MUHAMMADABAD GOHNA,MAUUTTAR PRADESH276403', 'dob': '1987-07-10', 'ladd': 'ROOM NO 16 NAVJEEVAN SOCIETYAKV MARG SANTOSH NAGARMUMBAI NORTH WEST,MUMBAI SUBURBANMAHARASHTRA400065', 'cname': 'Ayodhya Ramsagar Chauhan', 'fingerprint': 'cee6bdca75c9aac1c7c3e06a17e5729b26ec31704a4bc7bdb32c4105e232da4c', 'padd_pincode': 276403, 'state': 'Mumbai', 'mobile_1': 9137002511, 'mobile_2': 8976796768}},

  {'_index': 'new_spb', '_type': '_doc', '_id': 'add3e9758f6e85fdf24288b19a19491cff01a190f96fdc506fde3c9769a932f6', '_score': 1.0, '_source': {'fname': None, 'padd': None, 'dob': None, 'ladd': 'OBEROI EXQUISITE  GOREGAON EAST,MUMBAI400063MUMBAIMAHARASHTRA', 'cname': 'Puja Srivastava', 'fingerprint': 'add3e9758f6e85fdf24288b19a19491cff01a190f96fdc506fde3c9769a932f6', 'state': 'Mumbai', 'mobile_1': 9004000123, 'mobile_2': None}}, 

  {'_index': 'new_spb', '_type': '_doc', '_id': '1efa91c5fe228bb1d7fb0b4199e4bc70f3f7ab55d7f62f8bcae9d27a7e46109a', '_score': 1.0, '_source': {'fname': None, 'padd': 'OBEROI EXQUISITEGOREGAON EAST,MUMBAIMUMBAIMAHARASHTRA400063', 'dob': '1970-01-01', 'cname': 'Puja Srivastava', 'fingerprint': '1efa91c5fe228bb1d7fb0b4199e4bc70f3f7ab55d7f62f8bcae9d27a7e46109a', 'padd_pincode': 400063, 'state': 'Mumbai', 'mobile_1': 9004000123, 'mobile_2': None}}, 

  {'_index': 'new_spb', '_type': '_doc', '_id': '9bb462714ea7882c5972f120874920d9d28b818f16b3f0a6c6478fcc0c5eebe7', '_score': 1.0, '_source': {'ladd_pincode': 360360, 'fname': None, 'padd': None, 'dob': None, 'ladd': 'AMVARSHA DYING JETPUR RAJKOT   JETPUR GJ 360360', 'cname': 'Sanjay Kumar U Chaudhary', 'fingerprint': '9bb462714ea7882c5972f120874920d9d28b818f16b3f0a6c6478fcc0c5eebe7', 'state': None, 'mobile_1': 8308655111, 'mobile_2': None}}]}}

How i wanted data is something like below, rows which are matching to "8308655111" should come like below, so that I can just pick it with the key of my query(i.e. mobile number)

'8308655111':{
[
    {'_index': 'new_spb', '_type': '_doc', '_id': '37c8f7ab1197abb7f8855897e92eeb731968005723354ba61a4810e57d86f387', '_score': 1.0, '_source': {'ladd_pincode': 401506, 'fname': 'Upendra Chaudhary', 'padd': 'PLOT NO. J-85 VALIANT GLASS WORKS PVT LTD, NAVAPUR ROAD BOISAR, SALWAD TARAPUR TI, PALGHAR THANE-THANE MH 401506', 'dob': '1970-01-01', 'ladd': 'S/O: UPENDRA CHAUDHARY, PLOT NO. J-85 VALIANT GLASS WORKS PVT LTD NAVAPUR ROAD, BOISAR TARAPUR TI, PALGHAR SALWAD-THANE MH 401506', 'cname': 'Sanjaykumar Chaudhary', 'fingerprint': '37c8f7ab1197abb7f8855897e92eeb731968005723354ba61a4810e57d86f387', 'padd_pincode': 401506, 'state': 'Maharashtra', 'mobile_1': 8308655111, 'mobile_2': None}},
{'_index': 'new_spb', '_type': '_doc', '_id': '9bb462714ea7882c5972f120874920d9d28b818f16b3f0a6c6478fcc0c5eebe7', '_score': 1.0, '_source': {'ladd_pincode': 360360, 'fname': None, 'padd': None, 'dob': None, 'ladd': 'AMVARSHA DYING JETPUR RAJKOT   JETPUR GJ 360360', 'cname': 'Sanjay Kumar U Chaudhary', 'fingerprint': '9bb462714ea7882c5972f120874920d9d28b818f16b3f0a6c6478fcc0c5eebe7', 'state': None, 'mobile_1': 8308655111, 'mobile_2': None}}]}}

]
}

For Mobile Number - "9137002511" one record like below

'9137002511':{
[
{'_index': 'new_spb', '_type': '_doc', '_id': 'cee6bdca75c9aac1c7c3e06a17e5729b26ec31704a4bc7bdb32c4105e232da4c', '_score': 1.0, '_source': {'fname': 'Ramsagar', 'padd': ',MOHAMMADABAD GOHNASURHURPUR,MUHAMMADABAD GOHNA,MAUUTTAR PRADESH276403', 'dob': '1987-07-10', 'ladd': 'ROOM NO 16 NAVJEEVAN SOCIETYAKV MARG SANTOSH NAGARMUMBAI NORTH WEST,MUMBAI SUBURBANMAHARASHTRA400065', 'cname': 'Ayodhya Ramsagar Chauhan', 'fingerprint': 'cee6bdca75c9aac1c7c3e06a17e5729b26ec31704a4bc7bdb32c4105e232da4c', 'padd_pincode': 276403, 'state': 'Mumbai', 'mobile_1': 9137002511, 'mobile_2': 8976796768}}

]
}

and suppose I do not get a response for a particular match query then response should come blank as below - for mobile "9999999999"

'9999999999':{
[
]
}

Hi @Vijay_Gupta,

Do you mean launch several search request in one call?
if so here a link to the doc:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html

Thank you @gabriel_tessier, I am referring that, will let you know in case of any query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.