I have an index with the following structure.
{
"title": "Your top FIY tips",
"content": "Fix It Yourself in April 2012.",
"tags": [
{
"tagName": "Fix it yourself"
},
{
"tagName": "customer tips"
},
{
"tagName": "competition"
}
]
}
The mapping looks like
{
"articles": {
"mappings": {
"article": {
"properties": {
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"tags": {
"type": "nested",
"properties": {
"tagName": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
I am using the following DSL query to search on the "content" and "title" fields and narrow the results down by a certain "tagName". Then use aggregates to count the tagNames within that query.
GET /articles/_search
{
"from": 1,
"size": 10,
"aggs": {
"tags": {
"nested": {
"path": "tags"
},
"aggs": {
"tags-tagnames": {
"terms": {
"field": "tags.tagName.raw"
}
}
}
}
},
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "FIY",
"fields": [
"title",
"content"
]
}
},
{
"nested": {
"query": {
"terms": {
"tags.tagName": [
"competition"
]
}
},
"path": "tags"
}
}
]
}
}
}
The search query and filter of the "tagNames" works fine. However the aggregates is not quite working. It doesn't seem to include the nested query data within the results. The aggregate results that come back are just based on the multi match search.
How can I include the nested query within the aggregates.
Sample documents at
https://gist.github.com/anonymous/83bc2b1bfa0ac0d295d42297e1d76c00
GET {index}/_mappingreturn? Istagsmapped as anestedtype?competitionin the tag name and matchFIYin the title or content? Is that not what you're seeing?