gpt4 book ai didi

Elasticsearch:从分析字段的搜索结果中删除重复项

转载 作者:行者123 更新时间:2023-11-29 02:56:59 25 4
gpt4 key购买 nike

我的索引中有如下条目:

 ID   BuildingName  Postalcode Type
1 ABCD 1234 1
2 ABCD 7890 1

我需要删除出现在“BuildingName”字段中的重复项在搜索时(不是在索引处,因为您看到它们是两个不同的条目)。最后我只想看(任何具有搜索名称的建筑物)

ID   BuildingName  Postalcode Type
1 ABCD 1234 1

为什么我不能使用此处描述的字段折叠/聚合(Remove duplicate documents from a search in Elasticsearch)-> 因为我需要对 BuildingName 进行 n-gram 分析,而字段折叠/聚合仅适用于未分析的字段。

有什么方法可以做到这一点?所有帮助表示赞赏!谢谢!

最佳答案

将子字段添加到 BuildingName 字段,该字段应该是 not_analyzed 或使用分析器分析,如 keyword 不应更改文本很多。当您搜索 nGram-ed 的普通 BuildingName 字段时,聚合是在未更改的子字段上执行的:

  • 映射:
  "mappings": {
"test": {
"properties": {
"BuildingName": {
"type": "string",
"analyzer": "my_ngram_analyzer",
"fields": {
"notAnalyzed": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
  • 查询:
{
"query": {
"term": {
"BuildingName": {
"value": "ab"
}
}
},
"aggs": {
"unique": {
"terms": {
"field": "BuildingName.notAnalyzed",
"size": 10
},
"aggs": {
"sample": {
"top_hits": {
"size": 1
}
}
}
}
}
}

关于Elasticsearch:从分析字段的搜索结果中删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32622309/

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