gpt4 book ai didi

elasticsearch - ElasticSearch无法识别数字

转载 作者:行者123 更新时间:2023-12-03 01:34:22 25 4
gpt4 key购买 nike

我使用此配置进行搜索和映射:

PUT :9200/subscribers


{
"settings": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "autocomplete",
"filter": [
"lowercase"
]
},
"autocomplete_search": {
"tokenizer": "lowercase"
}
},
"tokenizer": {
"autocomplete": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10,
"token_chars": [
"letter",
"digit"
]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"id": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search"
},
"name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search"
},
"contact_number": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search"
}
}
}
}
}

但是当我添加新对象时:

POST :9200/subscribers/doc/?pretty


{
"id": "1421997",
"name": "John 333 Martin",
"contact_number":"+43fdsds*543254365"
}

如果我按类似的方式搜索多个字段

POST :9200/subscribers/doc/_search


{
"query": {
"multi_match": {
"query": "Joh",
"fields": [
"name",
"id",
"contact_number"
],
"type": "best_fields"
}
}
}

成功返回 "John 333 Martin"。但是当我这样做时: "query": "333""query": "+43fds""query": "14219",它什么也不返回。这很奇怪,因为我也为数字配置了过滤器:
 "token_chars": [
"letter",
"digit"
]

为了按所有字段进行搜索并查看带有数字的结果,该怎么办?

更新:

甚至 GET :9200/subscribers/_analyze
{
"analyzer": "autocomplete",
"text": "+43fdsds*543254365"
}

显示绝对正确的组合,例如 "43""43f""43fd""43fds"。但是搜索没有。可能是我的搜索查询不正确?

最佳答案

搜索使用的分析器与倒排索引中用于创建 token 的分析器不同。因为您将lowercase标记生成器用作search_analyzer,所以数字会被剥离。见下文

POST _analyze
{
"tokenizer": "lowercase",
"text": "+43fdsds*543254365"
}

产生
{
"tokens" : [
{
"token" : "fdsds",
"start_offset" : 3,
"end_offset" : 8,
"type" : "word",
"position" : 0
}
]
}

而是使用 standard分析器作为您的search_analyzer,即按如下所示修改映射,该映射将按预期工作
"mappings": {
"doc": {
"properties": {
"id": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"contact_number": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}

使用 standard分析器
POST _analyze
{
"analyzer": "standard",
"text": "+43fdsds*543254365"
}

产生
{
"tokens" : [
{
"token" : "43fdsds",
"start_offset" : 1,
"end_offset" : 8,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "543254365",
"start_offset" : 9,
"end_offset" : 18,
"type" : "<NUM>",
"position" : 1
}
]
}

关于elasticsearch - ElasticSearch无法识别数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53548451/

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