I ES 5.12
PUT testindex_51
{
"settings": {
"analysis": {
"analyzer": {
},
"filter":{
}
}
},
"mappings": {
"table1": {
"properties": {
"title": {
"type": "text",
"analyzer": "whitespace",
"fielddata": true
}
}
}
}
}
POST testindex_50/table1
{
"title" : "tag1 aggs1 blue"
}
POST testindex_50/table1
{
"title" : "tag2 aggs2 blue"
}
POST testindex_50/table1/_search
{
"aggs": {
"tags_count": {
"terms": {
"field": "title",
"size": 10
}
}
}
}
回答あなたは単にfielddata有効(汚いやり方)と同じを取得するには、単純な用語の集約を使用することができます
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"tags_count": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "blue",
"doc_count": 2
},
{
"key": "aggs1",
"doc_count": 1
},
{
"key": "aggs2",
"doc_count": 1
},
{
"key": "tag1",
"doc_count": 1
},
{
"key": "tag2",
"doc_count": 1
}
]
}
}
}
'tags'は単一の文字列ですか?それがタイプ[配列](https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html)だったら、それはケーキの一片でしょう。配列にすることができない場合は、[regex query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html)を使用して、 – dimzak