ES查询以匹配查询中尽可能多的单词

问题描述

索引中有几百万个文档。 我有一个句子,想检索与许多单词匹配的文档。我只需要搜索一个字段content

curl -X GET "xxx.com:9200/test/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "query" : {
        "bool" : { "must" : [{"term": {"content": {"value": "popular artworks of Banksy"}}}]
    }}
}
'

我希望查询中包含尽可能多的单词的文档越多越好。如果文档中的文字出现了许多艺术品,班克斯语和一些流行文字,则应将其打高分。 另外,是否可以将比其他单词更常见的单词的匹配权重降低?比Banksy更受欢迎。我知道我可以使用升压。但是我不想手动设置这些值。我希望对它有一个隐含的理解。

解决方法

添加包含索引数据,搜索查询和搜索结果的工作示例。

有关match_phrase查询和bool queries的ES文档,以获取详细说明。

索引数据:

{
    "content":"popular popular popular artworks artworks Banksy"
}
{
    "content":"popular artworks Banksy"
}
{
    "content":"popular popular artworks Banksy"
}
{
    "content": "popular artworks Banksy Banksy"
}
{
    "content": "popular popular popular artworks artworks artworks Banksy"
}

搜索查询:

    {
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "content": "popular artworks of Banksy"
          }
        },{
          "match_phrase":{
            "content":"popular artworks Banksy Banksy"
          }
        }
      ]
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "test1","_type": "_doc","_id": "4","_score": 0.4776722,"_source": {
          "content": "popular artworks Banksy Banksy"
        }
      },{
        "_index": "test1","_id": "5","_score": 0.22413516,"_source": {
          "content": "popular popular popular artworks artworks artworks Banksy"
        }
      },"_id": "1","_score": 0.22279418,"_source": {
          "content": "popular popular popular artworks artworks Banksy"
        }
      },"_id": "3","_score": 0.21652403,"_source": {
          "content": "popular popular artworks Banksy"
        }
      },"_id": "2","_score": 0.21318543,"_source": {
          "content": "popular artworks Banksy"
        }
      }
    ]

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...