基本问题与:Word-oriented completion suggester (ElasticSearch 5.x)
相同在这种情况下,单独的索引和最佳答案并不适合我。我有多个字段流入建议字段而不知道有多少字。 我建立了一个木瓦来相应地填写建议字段。
映射:
PUT test_index
{
"mappings": {
"my_type": {
"properties": {
"person": {
"type": "text"
},
"city": {
"type": "text"
},
"tags": {
"type": "keyword"
},
"suggest": {
"type": "completion"
}
}
}
}
}
建议字段包含(自我)匹配的" person"," city"和"标签"
POST test_index/my_type/_bulk
{"index":{}}
{ "person": "Michael Jackson", "city": "Far far away", "tags": "Rock", "suggest": ["michael", "michael jackson", "jackson", "far", "far away", "away", "rock", "concert"]}
{"index":{}}
{ "person": "Michelangelo Something", "city": "Any other place", "tags": "Artist", "suggest": ["michelangelo", "michelangelo something", "something", "any", "other place", "place", "artist"]}
{"index":{}}
{ "person": "Michael Middlename Jordan", "city": "Somewhere", "tags": ["Basketball", "Sport"], "suggest": ["michael", "michael middlename", "middlename", "middlename jordan", "jordan", "somewhwere", "basketball", "sport"]}
{"index":{}}
{ "person": "Robbie Williams Peterson", "city": "Far far away", "tags": ["Music", "Open Air"], "suggest": ["robbie", "robbie williams", "williams", "williams peterson", "peterson", "far", "far away", "away", "music", "open air"]}
现在正在寻找建议:
POST /test_index/_search?pretty
{
"_source": "suggest",
"suggest": {
"suggest": {
"text": "mic",
"completion": {
"field": "suggest"
}
}
}
}
以下结果:
"text": "mic",
"offset": 0,
"length": 3,
"options": [
{
"text": "michael",
"_index": "test_index",
"_type": "my_type",
"_id": "AVoJHAVtjkwxBtXDegO0",
"_score": 1,
"_source": {
"suggest": [
"michael",
"michael jackson",
"jackson",
"far",
"far away",
"away",
"rock",
"concert"
]
}
},
{
"text": "michael",
"_index": "test_index",
"_type": "my_type",
"_id": "AVoJHAVtjkwxBtXDegO2",
"_score": 1,
"_source": {
"suggest": [
"michael",
"michael middlename",
"middlename",
"middlename jordan",
"jordan",
"somewhwere",
"basketball",
"sport"
]
}
},
{
"text": "michelangelo",
"_index": "test_index",
"_type": "my_type",
"_id": "AVoJHAVtjkwxBtXDegO1",
"_score": 1,
"_source": {
"suggest": [
"michelangelo",
"michelangelo something",
"something",
"any",
"other place",
"place",
"artist"
]
}
}
]
}
我需要一种方法来对结果进行重复数据删除。一个" micheal"足够。此外,我想知道为什么得分始终为1.无论结果如何。