0

Something is not quite clear to me about aggregations on nested fields that are not arrays but simple objects.

Let's consider the simple case scenario where I have a nested fields with languages + the normalized_name (that acts as some sort of ID)

# index/_mapping
"tags": {
    "type": "nested",
    "properties": {
        "english": {
            "type": "text",
            "analyzer": "english"
        },
        "french": {
            "type": "text",
            "analyzer": "french_light"
        },
        "normalized": {
            "type": "keyword"
        }
    }
},

Given a search query Q, I want to aggregate the number of documents whose tag, in english OR french OR normalized match exactly my term (a document should be counted only once if it matches multiple fr/en/normalized nested fields but this does not really matter as english/french/normalized are all different case-sensitive wise (maybe not case-insensitive wise however) and use their tags.normalized as a key for my aggregation. I believe I have the filtering done right, but I'm still not getting any bucket...

Previously, when I had a single value I was doing

aggs: {tags: {terms: {field: "tag", size: 1000}}}}} 

When I read the doc, I see many references to nested aggregations but they all seem to be about nested aggregations inside aggregations, but I just want to aggregate the document count based on nested field. I have tried something like

aggs: {tag_names: {terms: {field: "tags.normalized", size: 100}}

...but it does not seem to work. Do I have to use the nested syntax ? I don't want to end up with results with nested aggregations, just to aggregate on a nested field...

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164

1 Answers1

0

Ah my bad, after a couple more tries and reading the doc more clearly, I realized a nested type for Elasticsearch was only a "nested array" and not a "nested object".

For nested objects I just needed to use type: :object in my mapping... everythings works well after this with aggs: {tag_names: {terms: {field: "tags.normalized", size: 100}}

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164