Elasticsearch: facet or aggregation returning doc counts over multiple fields -


i have elasticsearch document structure i'd have terms facet (or aggragation) obtain number of documents independently of field in appear.

for example, le following result shows both documents , facetted search result:

    {         "_shards": {             "failed": 0, "successful": 5, "total": 5         },         "hits": {             "hits": [                 {                     "_id": "003", "_index": "test", "_score": 1.0, "_type": "test",                     "_source": {                         "root": {                             "content": [                                 "five",                                 "five",                                 "five"                             ],                             "title": "four"                         }                     }                 },                 {                     "_id": "002", "_index": "test", "_score": 1.0, "_type": "test",                     "_source": {                         "root": {                             "content": "two three",                             "title": "three"                         }                     }                 },                 {                     "_id": "001", "_index": "test", "_score": 1.0, "_type": "test",                     "_source": {                         "root": {                             "content": "one two",                             "title": "one"                         }                     }                 }             ],             "max_score": 1.0, "total": 3         },         "facets": {             "terms": {                 "_type": "terms", "missing": 0, "other": 0,                 "terms": [                     {                         "count": 2,                         "term": "two"                     },                     {                         "count": 2,                         "term": "three"                     },                     {                         "count": 2,                         "term": "one"                     },                     {                         "count": 1,                         "term": "four"                     },                     {                         "count": 1,                         "term": "five"                     }                 ],                 "total": 8             }         },         "timed_out": false,         "took": 18,     } 

we can see terms "one" , "three" have counts of 2 (once each field of same doc) them have count of 1. term count of 2 should "two".

i looked aggregation see if doesn't seem work multiple fields (or have missed something).

it have been nice build "terms" facet on "root" rather individual fields... doesn't seem possible either.

any ideas, how work out ?

you can use script in terms aggregation achieve this. inside script , collect tokens both field , set union operation , return set.

{     "aggs" : {         "genders" : {             "terms" : {                 "script" : "union(doc['content'].values, doc['title'].values) "             }         }     } } 

you need see how apply union operation in whichever language use use script language.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -