elasticsearch:匹配查询可以得到结果,但更像是查询不能

时间:2014-04-28 08:26:52

标签: elasticsearch

我对弹性搜索查询有疑问:

我有两个文档,内容字段使用标准分析器,值为:

  1. "内容":"但巴菲特在富国银行的股份,以及约翰逊热门在其他一些主要银行的股份&#34

  2. "内容":" Taco Bell的主要信息约翰逊热 Fancher告诉Nation的餐厅新闻,手机是他们的主要现在关注"

  3. 当我使用匹配查询时,我可以获得这两个文档:

    localhost:9200/content/en-us/_search?pretty=true -d '
    {    
    "query" : {
        "match" : {
            "content" : "johnson hot"
        }
      } 
    }'
    

    但是我无法使用更像查询的方式:

    localhost:9200/content/en-us/_search?pretty=true -d '
    {
        "from": 0,
        "size": 200,
        "query": {
            "more_like_this_field": {
                "content": {
                    "like_text": "johnson hot",
                    "min_term_freq": 1,
                    "max_query_terms": 12
                 }
            }
        }
    }'
    

    结果:

    "hits" : {
        "total" : 0,
        "max_score" : null,
        "hits" : [ ]
    }
    

    有人知道为什么吗? 是否更类似于"类似"在SQL?

    由于 约翰逊

1 个答案:

答案 0 :(得分:0)

更像是这个字段查询会通过匹配指定字段的内容为您提供类似的文档。

您必须将 min_doc_freq 设置为1.默认值为5,因此它会忽略 like_text中的条件它们不会出现超过5个文档。由于您只有两个文档,因此将忽略术语 jhonson hot 。以下查询将起作用

curl 'http://localhost:9200/content/en-us/_search?pretty=true' -d '{
  "from": 0,
  "size": 200,
  "query": {
    "more_like_this_field": {
      "content": {
        "like_text": "johnson hot",
        "min_term_freq": 1,
        "max_query_terms": 12,
        "min_doc_freq": 1
      }
    }
  }
}'