gpt4 book ai didi

elasticsearch - Elasticsearch Ngram查询不起作用

转载 作者:行者123 更新时间:2023-12-03 00:35:22 24 4
gpt4 key购买 nike

我从elasticsearch 2.0移到5.2,ngram搜索现在坏了!

elasticsearch设置就在下面,它只是用于标题和摘要字段的简单ngram标记器。

settings = {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 10
}
},
"analyzer": {
"search_ngram_analyzer": {
"tokenizer": "standard",
"type": "custom",
"filter": ["standard", "lowercase", "stop", "asciifolding"]
},

"index_ngram_analyzer": {
"tokenizer": "standard",
"type": "custom",
"filter": ["standard", "lowercase", "stop", "asciifolding", "ngram_filter"]
}
}
},

},
"mappings": {
"docs": {
"properties": {
'title': {
'boost': 100.0,
'search_analyzer': 'search_ngram_analyzer',
'analyzer': 'index_ngram_analyzer',
'type': 'text',
},
'summary': {
'boost': 20.0,
'search_analyzer': 'search_ngram_analyzer',
'analyzer': 'index_ngram_analyzer',
'type': 'text',
}
}
}

}
}
http://localhost:9200/my_index/_search?q=example返回其中包含单词“example”的文档。作为常规查询。

然而, http://localhost:9200/my_index/_search?q=exampl(例如,带有“e”)返回一个空对象!

我在安装程序中找不到错误。这是API中断吗?

最佳答案

您确定这在以前的版本中有效吗?

如果您使用URI搜索并且未指定字段(就像在http://localhost:9200/my_index/_search?q=exampl中所做的那样),那么将使用_all字段。它使用标准分析器,因此没有ngram。您要使用的查询是/my_index/_search?q=title:exampl
为了重现性,这是Console整个示例的转储:

PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 10
}
},
"analyzer": {
"search_ngram_analyzer": {
"tokenizer": "standard",
"type": "custom",
"filter": [
"standard",
"lowercase",
"stop",
"asciifolding"
]
},
"index_ngram_analyzer": {
"tokenizer": "standard",
"type": "custom",
"filter": [
"standard",
"lowercase",
"stop",
"asciifolding",
"ngram_filter"
]
}
}
}
},
"mappings": {
"docs": {
"properties": {
"title": {
"boost": 100,
"search_analyzer": "search_ngram_analyzer",
"analyzer": "index_ngram_analyzer",
"type": "text"
},
"summary": {
"boost": 20,
"search_analyzer": "search_ngram_analyzer",
"analyzer": "index_ngram_analyzer",
"type": "text"
}
}
}
}
}


GET /my_index/_analyze
{
"analyzer": "index_ngram_analyzer",
"text": "example exampl"
}
GET /my_index/_analyze
{
"analyzer": "search_ngram_analyzer",
"text": "example exampl"
}

POST /my_index/docs
{
"title": "This is an example",
"summary": "Some more text"
}

GET /my_index/_search?q=example
GET /my_index/_search?q=exampl
GET /my_index/_search?q=title:exampl

DELETE /my_index

关于elasticsearch - Elasticsearch Ngram查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42327791/

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