Search code examples
elasticsearchnestelasticsearch-netelasticsearch-query

Multiple filter by array of object in Elastic 6.*


Need help with building query through the array in ElasticSearch 6. I have documents that represent some property units with a number of attributes:

{  
   "Unit":{
     "Attributes":{  
        "Attribute":[  
           {  
              "Name":"Elevator",
              "Text":"No"
           },
           {  
              "Name":"Pet Friendly",
              "Text":"Yes"
           }
        ...
        ]   
      }        
   }
}

How can I filter my documents to find all pet friendly units or all units without elevator?

P.S. I am using NEST.


Solution

  • Map Attribute as a nested type, probably with Text mapped as keyword for term level matching. To query, use a bool query with filter clauses, where the clauses will be nested queries.