elasticsearch - Finding nested result of a certain parent -


i have following query works in giving me periods (nested) +houses belong have arrivaldate period specify. want try , arrivaldates house, cannot figure out syntax of how in elasticsearch.

get /houses/house/_search {   "_source" : ["houseid"],  "query": {  "nested": {   "path": "periods",   "query": {     "bool": {       "must": [         {"range": {           "periods.arrivaldate": {           "gte" : "2017-10-01",           "lt" : "2017-11-01"          }         }        }      ]     }   }, "inner_hits" : {} } 

} }

the mapping (shortened hope relevant parts)

{ "houses": {   "mappings": {      "house": {         "properties": {            "periods": {               "type": "nested",               "properties": {                  "arrivaldate": {                     "type": "date",                     "format": "yyyy-mm-dd"                  },   ....            "houseid": {               "type": "keyword"            }, 

so find available arrivaldates house houseid within month

i think have figured out, please let me know if better solutions available:

{ "_source":[   "housecode",   "country",   "region" ], "query":{   "bool":{      "must":[         {            "match":{               "houseid":"someid"            }         },         {            "nested":{               "path":"periods",               "query":{                  "range":{                     "periods.arrivaldate":{                        "gte":"2017-05-01",                        "lt":"2017-06-01"                     }                  }               },               "inner_hits":{                  "size":1000               }            }         }      ]   }  } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -