How to filter nested documents in elasticsearch? -
i have documents looks
{ "_id": "56161cb3cbdad2e3b437fdc3", "_type": "comunity", "name": "public", "data": [ { "title": "sonder", "creationdate": "2015-08-22t03:43:28 -03:00", "quantity": 0 }, { "title": "vule", "creationdate": "2014-05-17t12:35:01 -03:00", "quantity": 0 }, { "title": "omer", "creationdate": "2015-01-31t04:54:19 -02:00", "quantity": 3 }, { "title": "sonder", "creationdate": "2014-05-22t05:09:36 -03:00", "quantity": 3 } ] }
the mapping:
comunitydocument": { "_source": { "includes": [ "meta.*" ] }, "properties": { "doc": { "dynamic": "false", "properties": { "data": { "type": "nested", "include_in_parent": true, "properties": { "title": { "type": "string" }, "creationdate": { "type": "date", "format": "dateoptionaltime" }, "quantity": { "type": "integer" } } }, "name": { "type": "string", "index": "not_analyzed" } } }, "meta": { "include_in_all": false, "properties": { "expiration": { "type": "long", "include_in_all": false }, "flags": { "type": "long", "include_in_all": false }, "id": { "type": "string", "include_in_all": false }, "rev": { "type": "string", "include_in_all": false } } } } }
and query
{ "size": 0, "aggs": { "filteragg": { "filter": { "nested": { "path": "comunitydocument.doc.data", "filter": { "terms": { "comunitydocument.doc.data.quantity": [ 0 ] } } } } } } }
as result have count of "data" documents quantity equal 0 don't it. strange thing nested aggregations works not nested filters.
if comunitydocument
type, correct query should be
{ "size": 0, "aggs": { "filteragg": { "filter": { "nested": { "path": "doc.data", "filter": { "terms": { "doc.data.quantity": [ 0 ] } } } } } } }
Comments
Post a Comment