gpt4 book ai didi

Elasticsearch:查找有和没有空格的值

转载 作者:行者123 更新时间:2023-12-04 08:11:25 25 4
gpt4 key购买 nike

我们有一些带有文章编号的字段。这篇文章编号看起来像 AB 987 g567 323。当我搜索“AB 987 g”时,我找到了正确的产品,但是当我搜索时没有空格,我什么也没找到。我试过pattern_replace,但它不起作用。

"whitespace_filter": {
"alphabets_char_filter": {
"type": "pattern_replace",
"pattern": " ",
"replacement": ""
}
如何搜索带有和不带有空格的文章编号?

最佳答案

您需要使用 edge_ngram连同 char_filter , 实现您的用例
添加一个工作示例
索引映射:

{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer",
"char_filter": [
"replace_whitespace"
]
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10,
"token_chars": [
"letter",
"digit"
]
}
},
"char_filter": {
"replace_whitespace": {
"type": "mapping",
"mappings": [
"\\u0020=>"
]
}
}
}
},
"mappings": {
"properties": {
"articlenumbers": {
"type": "text",
"fields": {
"analyzed": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
}
索引数据:
{
"articlenumbers": "AB 987 g567 323"
}
查询查询:
{
"query": {
"multi_match": {
"query": "AB987g",
"fields": [
"articlenumbers",
"articlenumbers.analyzed"
]
}
}
}
搜索结果:
"hits": [
{
"_index": "65936531",
"_type": "_doc",
"_id": "1",
"_score": 1.4384104,
"_source": {
"articlenumbers": "AB 987 g567 323"
}
}
]

关于Elasticsearch:查找有和没有空格的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65936531/

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