【问题标题】:Is it possible to use a more-like-this query on nested fields?是否可以在嵌套字段上使用更像这样的查询?
【发布时间】:2022-04-19 14:12:47
【问题描述】:

我有一个基于(嵌套)新闻文章的“事件”类型,包括标题和文本,它们都具有多字段。

我试过了:

{
  "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"
              }
          }]
        }
      }
    }
  }
}

但它总是返回 0 次点击

【问题讨论】:

    标签: elasticsearch nested morelikethis


    【解决方案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
                }
            }
        }
    }
    

    这对我有用,考虑到您使用的嵌套字段的映射必须定义为术语向量。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 2016-03-31
      • 2015-10-18
      • 2013-09-13
      • 2011-12-01
      • 1970-01-01
      • 2017-10-02
      相关资源
      最近更新 更多