Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying multiple nested objects on multiple paths

Is it possible to query multiple nested objects on different paths in Elasticsearch? I can query one nested object on one path but I can't find the correct syntax to query two objects on different paths.

I need to query with the logic like the following:

{'query': {
   'bool': {
       'must': [
           'nested': {
               'path': 'Diagnosis',
               'query': {
                   'bool': {
                       'must': [{'match_phrase': {'Diagnosis.Diagnosis': {'query': "epidemia"}}}]
                   }  
               }
           },
           'nested': {
               'path': 'Demographic',
               'query': {
                   'bool': {
                       'must': [{'match_phrase': {'Demographic.Gender': {'query': "female"}}}]
                   }  
               }
           }
       ]
   }
}}

The ultimate goal is to denormalize my PostgreSQL DB data (72 tables, over 1600 columns in total) and be able to use boolean queries over it.

like image 970
srgbnd Avatar asked Sep 15 '16 21:09

srgbnd


1 Answers

It works, I missed curly brackets around nested query. The correct way:

{'query': {
   'bool': {
       'must': [
           {'nested': {
               'path': 'Diagnosis',
               'query': {
                   'bool': {
                       'must': [{'match_phrase': {'Diagnosis.Diagnosis': {'query': "epidemia"}}}]
                   }  
               }
           }},
           {'nested': {
               'path': 'Demographic',
               'query': {
                   'bool': {
                       'must': [{'match_phrase': {'Demographic.Gender': {'query': "female"}}}]
                   }  
               }
           }}
       ]
   }
}}
like image 54
srgbnd Avatar answered Sep 28 '22 05:09

srgbnd