gpt4 book ai didi

elasticsearch - 获得有关Elasticsearch领域的建议

转载 作者:行者123 更新时间:2023-12-02 22:31:50 25 4
gpt4 key购买 nike

我正在尝试使用Elasticsearch提出建议功能。
在本文之后https://qbox.io/blog/multi-field-partial-word-autocomplete-in-elasticsearch-using-ngrams

我现在所拥有的有效,但不适用于同一句子中的两个单词。

我现在在ES中拥有的数据是。

{
"_index": "books",
"_type": "book",
"_id": "AVJp8p4ZTfM-Ee45GnF5",
"_score": 1,
"_source": {
"title": "Making a dish",
"author": "Jim haunter"
}
},
{
"_index": "books",
"_type": "book",
"_id": "AVJp8jaZTfM-Ee45GnF4",
"_score": 1,
"_source": {
"title": "The big fish",
"author": "Jane Stewart"
}
},
{
"_index": "books",
"_type": "book",
"_id": "AVJp8clRTfM-Ee45GnF3",
"_score": 1,
"_source": {
"title": "The Hunter",
"author": "Jame Franco"
}
}

这是映射和设置。
{"settings": {
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter",
"digit"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"books": {
"_all": {
"index_analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"title": {
"type": "string",
"index": "no"
},
"author": {
"type": "string",
"index": "no"
}
}
}
}
}

这是搜索
{
"size": 10,
"query": {
"match": {
"_all": {
"query": "Hunter",
"operator": "and",
"fuzziness": 1
}
}
}
}

当我搜索“The”时,
“大鱼”和
“猎人”。
但是,当我输入“The Hunt”时,我什么也没得到。
要再次获得该书,我需要输入“The Hunte”。
有什么建议么?
任何帮助表示赞赏。

最佳答案

从字段中删除"index": "no"对我有用。另外,由于我使用的是ES 2.x,因此必须用"analyzer"替换“index_analyzer”。所以这是映射:

PUT /test_index
{
"settings": {
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter",
"digit"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"books": {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"title": {
"type": "string"
},
"author": {
"type": "string"
}
}
}
}
}

这是我用来测试的一些代码:

http://sense.qbox.io/gist/0140ee0f5043f66e76cc3109a18d573c1d09280b

关于elasticsearch - 获得有关Elasticsearch领域的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34950676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com