elasticsearch - Elasticsearch 文档字段中的所有术语都应与查询匹配
问题描述
我在弹性索引中有一个包含多个单词的字段。IE
field : "nice house"
我只想查找文档,如果用户在他的查询字符串中包含该字段的所有单词,则查询字符串可能包含不在该字段中的其他单词,即
nice (should not match)
nice room (should not match)
nice house (should match)
nice house bro (should match)
minimum_should match or AND don't help here任何提示如何解决这个问题
解决方案
没有直接的方法可以实现您的用例。但是您可以使用渗透查询来实现您的用例
添加具有索引数据、映射、搜索查询和搜索结果的工作示例
索引映射:
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
指数数据:
{
"query": {
"match": {
"name": {
"query": "nice house",
"operator": "AND"
}
}
}
}
搜索查询:
不错(不应该匹配)
{
"query": {
"percolate": {
"field": "query",
"document": {
"name": "nice"
}
}
}
}
搜索结果将是:
"hits": []
好房子兄弟(应该匹配)
{
"query": {
"percolate": {
"field": "query",
"document": {
"name": "nice house bro"
}
}
}
}
搜索结果将是
"hits": [
{
"_index": "67433387",
"_type": "_doc",
"_id": "1",
"_score": 0.26152915,
"_source": {
"query": {
"match": {
"name": {
"query": "nice house",
"operator": "AND"
}
}
}
},
"fields": {
"_percolator_document_slot": [
0
]
}
}
]
推荐阅读
- r - 是否有用于计算具有阈值(maxDist)的快速 Levenshtein 距离的 R 函数
- c# - 如何从 C# 和 XAML 控制情节提要动画
- javascript - 如何在自动完成中设置默认选定项目
- flutter - 如何检查用户是否在 Flutter 中启用了漫游
- ethereum - Web3 调用 Transfer 而不是 SendRawTransaction
- html - 页面顶部和 html 内容之间的空间
- amazon-web-services - AWS beanstalk 在下载 tensorflow==2.4.0 时无法安装 pip 必备项
- sql - 如何解析 JSON 中的多个参数?
- unity3d - 如何正确地将游戏对象添加到动画装备
- python - 如何修复创建文本身份验证代理 polkit 时出错?