gpt4 book ai didi

elasticsearch - 无法在Elasticsearch 5.4中搜索短语

转载 作者:行者123 更新时间:2023-12-03 00:55:20 27 4
gpt4 key购买 nike

我正在搜索电子邮件正文中的短语。需要过滤出准确的数据,例如,如果我搜索“Avenue New”,它应该仅返回带有短语“Avenue New”的结果,而不是“Avenue Street”,“Park Avenue”等

我的映射就像:

{
"exchangemailssql": {
"aliases": {},
"mappings": {
"email": {
"dynamic_templates": [
{
"_default": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"doc_values": true,
"type": "keyword"
}
}
}
],
"properties": {
"attachments": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"body": {
"type": "text",
"analyzer": "keylower",
"fielddata": true
},

"count": {
"type": "short"
},
"emailId": {
"type": "long"
}
}
}
},
"settings": {
"index": {
"refresh_interval": "3s",
"number_of_shards": "1",
"provided_name": "exchangemailssql",
"creation_date": "1500527793230",
"analysis": {
"filter": {
"nGram": {
"min_gram": "4",
"side": "front",
"type": "edge_ngram",
"max_gram": "100"
}
},
"analyzer": {
"keylower": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "keyword"
},
"email": {
"filter": [
"lowercase",
"unique",
"nGram"
],
"type": "custom",
"tokenizer": "uax_url_email"
},
"full": {
"filter": [
"lowercase",
"snowball",
"nGram"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "0",
"uuid": "2XTpHmwaQF65PNkCQCmcVQ",
"version": {
"created": "5040099"
}
}
}
}
}

我给搜索查询像:
{
"query": {
"match_phrase": {
"body": "Avenue New"
}
},
"highlight": {
"fields" : {
"body" : {}
}
}
}

最佳答案

这里的问题是您要使用关键字tokenizer对整个内容进行标记,即它将是一个大写的小写字符串,并且您无法在其中搜索。

如果仅将body字段的分析器更改为standard而不是keylower,则可以使用match_phrase查询找到所需的内容。

       "body": {
"type": "text",
"analyzer": "standard", <---change this
"fielddata": true
},

关于elasticsearch - 无法在Elasticsearch 5.4中搜索短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45205946/

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