question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terms Aggregation KeyAsString is always null

See original GitHub issue

NEST/Elasticsearch.Net version:2.4.6

Elasticsearch version: “version” : { “number” : “2.4.1”, “build_hash” : “c67dc32e24162035d18d6fe1e952c4cbcbe79d16”, “build_timestamp” : “2016-09-27T18:57:55Z”, “build_snapshot” : false, “lucene_version” : “5.5.2” },

Description of the problem including expected versus actual behavior:

Steps to reproduce:

  1. run Search with Terms aggregation on one of the object properties of type Guid
    for example object like : {name: ‘SOME NAME’ guidVal: ‘034a7b09-9fee-4f63-a87f-4592edd9560d’}

var aggResponse =  client.Search<TestClass>(s=>            
s.Aggregations(a => a.Terms("distinc_bus", ad => ad.Field(t => t.guidVal))));

List<Guid> listOfGuids = aggResponse.Aggs.Terms("distinc_bus").Buckets.Select(b => Guid.Parse(b.Key)).ToList(); //this line will throw as key is not returned as valid Guid
  1. expected result : you get bucket that the bucket key ,or at least the KeyAsString is the same as the guidVal (i.e. ‘034a7b09-9fee-4f63-a87f-4592edd9560d’).
  2. actual result : the bucket key is only the last token of the Guid : “4592edd9560d”, and the KeyAsString is null (the value returned fine when reading a single document with Get() or multiple with Search() with no aggregations , so it is saved fine on the Elastic search itself)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
djnelson9715commented, Nov 19, 2016

if look at the mapping for this type,

yourindex/_mapping

        "properties": {
           "Id": {
              "type": "string",
              "index": "not_analyzed"
           },

you need to add the index setting. This is very good practice to use non-analyzed fields for terms aggregations.

On Sat, Nov 19, 2016 at 11:15 AM, Amir Sasson notifications@github.com wrote:

How can the analyzer be disabled for this aggregation only?

On Nov 19, 2016 19:07, “djnelson9715” notifications@github.com wrote:

Amir,

I think the issue you are having is because your guidVal property is being analyzed which results in the quid fragments being used by the terms aggregation.

On Sat, Nov 19, 2016 at 9:34 AM, Amir Sasson notifications@github.com wrote:

NEST/Elasticsearch.Net version:2.4.6

Elasticsearch version: “version” : { “number” : “2.4.1”, “build_hash” : “c67dc32e24162035d18d6fe1e952c4cbcbe79d16”, “build_timestamp” : “2016-09-27T18:57:55Z”, “build_snapshot” : false, “lucene_version” : “5.5.2” },

Description of the problem including expected versus actual behavior:

Steps to reproduce:

  1. run Search with Terms aggregation on one of the object properties of type Guid for example object like : {name: ‘SOME NAME’ guidVal: ‘034a7b09-9fee-4f63-a87f-4592edd9560d’}

var aggResponse = client.Search(s=> s.Aggregations(a => a.Terms(“distinc_bus”, ad => ad.Field(t => t.guidVal))));

aggResponse .Aggs.Terms(“distinc_bus”).Buckets.Select(b => Guid.Parse(b.Key)).ToList(); //this line will throw as key is not returned as valid Guid

  1. expected result : you get bucket that the bucket key ,or at least the KeyAsString is the same as the guidVal (i.e. ‘034a7b09-9fee-4f63-a87f- 4592edd9560d’).
  2. actual result : the bucket is only the last token of the Guid : “4592edd9560d”, and the KeyAsString is null

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/elastic/elasticsearch-net/issues/2393, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABy19V- A4zX6WeEQVNVbktXf32hHX_1Hks5q_xcTgaJpZM4K3SD0> .

Doug Nelson

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/elastic/elasticsearch-net/issues/2393# issuecomment-261725829>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AKxwHKo5Q1cS9Q- PNBojPbTUCya9VNaMks5q_yztgaJpZM4K3SD0> .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/elastic/elasticsearch-net/issues/2393#issuecomment-261726326, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy19WpTr9LpAKUMDji4152o-T1Fr_Neks5q_y7MgaJpZM4K3SD0 .

Doug Nelson

0reactions
russcamcommented, Nov 30, 2016

Meant to add that .KeyAsString maps to the value returned by Elasticsearch in the "key_as_string" property of a bucket; for some keys such as dates, Elasticsearch returns a "key_as_string" property as well as the numerical epoch time as the key. In NEST, we always read the "key" as a string, but #2336 is an issue to look at supporting any returned json value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyAsString is null using aggregations - Elasticsearch
Hi, I'm using Elastic 6.0.0. Using aggregations for the first time and I'm having some trouble with it. My documents look something like ......
Read more >
Elasticsearch terms aggregation returns no buckets
New elasticsearch user here and having an issue with a terms aggregation. I have indexed 187 documents with fields like "name","host","risk" ...
Read more >
Elastic - Go Packages
type Aggregation interface { // Source returns a JSON-serializable aggregation that is a fragment // of the request sent to Elasticsearch.
Read more >
Bucket Aggregations - Open Distro Documentation
The terms aggregation returns the top unique terms. So, if the data has many unique terms, then some of them might not appear...
Read more >
Elasticsearch - A Complete Guide - StudyLib
One should be careful while configuring default values for null. The default value should always be of the type corresponding to the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found