1

我刚刚发现了“more_like_this”查询类型并尝试将它与我的嵌套对象一起使用。不幸的是,这个查询似乎无法在嵌套对象中搜索。这是我的映射:

"Presentation": {
    "properties": {
      "id": {
        "include_in_all": false,
        "type": "string"
      },
      "title": {
        "include_in_all": true,
        "type": "string"
      },
      "description": {
        "include_in_all": true,
        "type": "string"
      },
      "categories": {
        "properties": {
          "id": {
            "include_in_all": false,
            "type": "string"
          },
          "category": {
            "include_in_all": true,
            "type": "string"
          },
          "category_suggest": {
            "properties": {
              "input": {
                "type": "string"
              },
              "payload": {
                "properties": {
                  "id": {
                    "type": "long"
                  }
                }
              }
            }
          }
        },
        "type": "nested"
      }
    }
  }

我的目标是找到所有与 id "96" 相关的演示文稿,并提升与 "96" 具有相同类别的演示文稿。但是,在执行下面的查询时,Elasticsearch 只计算“标题”和“描述”字段的分数(而不是查看“类别”)。

{
  "size": 4,
  "query": {
    "more_like_this": {
      "like": [
        {
          "_index": "client",
          "_type": "Presentation",
          "_id": "96"
        }
      ],
      "min_term_freq": 1,
      "max_query_terms": 35,
      "min_word_length": 3,
      "minimum_should_match": "1%"
    }
  }
} 

我也尝试在嵌套字段上强制查询,但它也不起作用:

{
  "size": 4,
  "query": {
    "bool": {
      "should": [
        {
          "more_like_this": {
            "like": [
              {
                "_index": "client",
                "_type": "Presentation",
                "_id": "96"
              }
            ],
            "min_term_freq": 1,
            "max_query_terms": 35,
            "min_word_length": 3,
            "minimum_should_match": "1%"                   
          }
        },
        {
            "nested" : {
                "path":"categories",
                "query" : {
                    "more_like_this": {
                        "like": [
                          {
                            "_index": "client",
                            "_type": "Presentation",
                            "_id": "96"
                          }
                        ],
                        "min_term_freq": 1,
                        "max_query_terms": 35,
                        "min_word_length": 3,
                        "minimum_should_match": "1%"
                    }
                }
            }
        }
      ]
    }
  }
}

我发现这个人有同样的问题,但使用的是旧版本的 elasticsearch:ElasticSearch More_Like_This API 和嵌套对象属性 ,不幸的是,没有给出可以与 ES 2.x 一起使用的答案(除了展平整个索引,我做不到)。

你们中有人对这个(奇怪的)问题有任何想法吗?谢谢 :)

4

3 回答 3

0

尝试将"term_vector": "yes"属性放入映射中。

根据文档

执行 MLT 的字段必须被索引并且类型为字符串。此外,当对文档使用 like 时,必须启用 _source 或者必须存储字段或存储 term_vector。为了加快分析速度,它可以帮助在索引时存储术语向量。

于 2017-07-25T12:28:01.403 回答
0

我相信您可以指定要搜索的字段。您可以尝试直接指向嵌套变量。像这样的东西

{
  "size": 4,
  "query": {
    "more_like_this": {
      "fields": ["id", "title", "description", "categories.id","categories.description", etc...]
      "like": [
        {
          "_index": "client",
          "_type": "Presentation",
          "_id": "96"
        }
      ],
      "min_term_freq": 1,
      "max_query_terms": 35,
      "min_word_length": 3,
      "minimum_should_match": "1%"
    }
  }
}
于 2016-06-09T18:39:23.860 回答
0

我在 ES 5.3 上遇到同样的问题(我希望从文档和嵌套文档中计算 MLT)。

您的 boolshould解决方案非常有帮助——我试图在一个 MLT 查询中进行连接,但不知道该怎么做。

fields通过在嵌套的 MLT 查询中指定,我能够让它工作(或者至少它似乎工作正常) 。因此,对于您的情况,您将添加:

"fields": ["categories.*"]

到嵌套的 MLT 查询。不确定这是否适用于 2.x,但认为它会被提及。

于 2017-04-06T16:46:27.447 回答