gpt4 book ai didi

elasticsearch - Elasticsearch忽略特殊字符

转载 作者:行者123 更新时间:2023-12-03 02:38:26 26 4
gpt4 key购买 nike

elasticsearch中的单词搜索工作正常,但似乎忽略了所有特殊字符。例如,我有此数据(123)苹果和123 pear ,但是当我查询“(123)”时,我希望“(123)苹果”是第一个出现的数据,而不是“123 pear ”。我试图将tokeniser从标准 token 生成器更改为空白 token 生成器,但仍然无法正常工作。好心劝告。谢谢!

Data: 
(123) apple
123 pear

Query: "(123)"

Expected:
(123) apple
123 pear

Actual result:
123 pear
(123) apple

最佳答案

我尝试了空白 token 生成器,它的工作原理

PUT /index25
{
"mappings": {
"properties": {
"message":{
"type": "text",
"analyzer": "my_analyzer"
}
}
},
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
}
}
}


数据:
 [
{
"_index" : "index25",
"_type" : "_doc",
"_id" : "cIC70m0BD5PlkoxX1O0B",
"_score" : 1.0,
"_source" : {
"message" : "123 pear"
}
},
{
"_index" : "index25",
"_type" : "_doc",
"_id" : "cYC70m0BD5PlkoxX9-3n",
"_score" : 1.0,
"_source" : {
"message" : "(123) apple"
}
}
]

查询:
GET index25/_search
{
"query": {
"match": {
"message": "(123)"
}
}
}

响应:
 [
{
"_index" : "index25",
"_type" : "_doc",
"_id" : "cYC70m0BD5PlkoxX9-3n",
"_score" : 0.47000363,
"_source" : {
"message" : "(123) apple"
}
}
]

查询:
GET index25/_search
{
"query": {
"match": {
"message": "123"
}
}
}

响应:
 [
{
"_index" : "index25",
"_type" : "_doc",
"_id" : "cIC70m0BD5PlkoxX1O0B",
"_score" : 0.9808292,
"_source" : {
"message" : "123 pear"
}
}
]

关于elasticsearch - Elasticsearch忽略特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58405299/

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