ElasticSearch C# client (NEST): access nested aggregation with Spaces -
assuming 2 values "red square" , "green circle", when run aggregation using elastic search 4 values instead of 2, space separated? red, square, green, circle. there way 2 original values.
the code below:
var result = this.client.search<myclass>(s => s .size(int.maxvalue) .aggregations(a => .terms("field1", t => t.field(k => k.myfield)) ) ); var agbucket = (bucket)result.aggregations["field1"]; var myagg = result.aggs.terms("field1"); ilist<keyitem> list = myagg.items; foreach (keyitem in list) { string data = i.key; }
in mapping, need set field1 string not_analyzed, this:
{ "your_type": { "properties": { "field1": { "type": "string", "index": "not_analyzed" } } } } you can make field1 multi-field , make both analyzed , not_analyzed best of both worlds (i.e. text matching on analyzed field + aggregation on exact value of not_analyzed raw sub-field).
{ "your_type": { "properties": { "field1": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } if choose second option, you'll need run aggregation on field1.raw instead of field1.
Comments
Post a Comment