Dear ES community,
I hope someone can help me out with a (honestly) very basic question. I’m posting this because I couldn’t find a simple answer, to my surprise.
Let’s say I have a blog post indexed in ES (example below). Please note that the tags field contains both tag ID an label.
{
title: "Blog Post A",
text: "…",
tags: [
{label: "Tag B", id: 1},
{label: "Tag C", id: 2}
]
}
My scheme looks like this, accordingly:
{
title: { type: "text" },
text: { type: "text" },
tags: {
type: "nested",
fields: {
label: {
type: "text",
fields: {
raw: {
type: "keyword"
}
}
},
id: {
type: "keyword"
}
}
}
}
Here’s my problem: I’d like to aggregate blog posts by tag, displaying the tag’s label, but using the ID for filtering.
Using the ID would solve some issues in my multi-language environment.
My aggregation currently looks like the snippet below. My issue is that an aggregation like this doesn’t return the tag‘s ID.
What I’d need is one facet per tag, containing both ID and label.
Can anybody point me in a direction on how to do this?
Here’s my aggregation:
aggs: {
tags: {
terms: {
field: "tags.label.raw" }
}
}
}