Is it possible to use a more-like-this query on nested fields?

老子叫甜甜 提交于 2019-12-08 12:46:27

问题


I have an "event" type based on a (nested) press article, including the title, and the text, which both have multifields.

I've tried :

{
  "query":{
    "nested":{
      "path":"article",
      "query":{
        "mlt":{
          "fields":["article.title.search","article.text.search"],
          "max_query_terms": 20,
          "min_term_freq": 1,
          "include": "false",
          "like":[{
              "_index":"myindex",
              "_type":"event",
              "doc":{
                "article":{
                  "title":"this is the title",
                  "text":"this is the body of the article"
              }
          }]
        }
      }
    }
  }
}

But it always returns 0 hits


回答1:


{
"query": {
    "nested":{
        "path":"articles",
        "query":{
            "more_like_this" : {
                "fields" : ["articles.brand", "articles.category", "articles.material"],
                "like" : [
                {
                    "_index" : "$index",
                    "_type" : "$type",
                    "_id" : "$id"
                }
                ],
                "min_term_freq" : 1,
                "max_query_terms" : 20
            }
        }
    }
}

This Works for me, Taking in consideration that the mapping of the nested fields you are using must be defined as term vectors.

"brand": {
            "type": "string",
            "index": "not_analyzed",
            "term_vector": "yes"
          }

Refer to: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html



来源:https://stackoverflow.com/questions/39124066/is-it-possible-to-use-a-more-like-this-query-on-nested-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!