ElasticSearch More_Like_This API和嵌套对象属性 [英] ElasticSearch More_Like_This API and Nested Object Properties

查看:173
本文介绍了ElasticSearch More_Like_This API和嵌套对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ES还是很陌生,所以如果这是我尚未发现的常见情况,请原谅我。

I'm fairly new to ES so forgive me if this is a common scenario that I haven't discovered yet.

我有一个包含以下内容的索引文档和每个文档都可以与特定事件相关,因此我在每个文档中都有一个嵌套的事件对象。事件->文档是一对多的关系。

I've got an index which contains documents and each document can be related to a specific event, so I have a nested event object in each document. Event -> Document is a one-to-many relationship.

当我显示单个文档时,我想显示更像这样,其中更像-实际上,这代表着来自同一会议,同一作者或同一主题的更多文档。
作者和主题可以正常工作,但是尽管mlt_fields接受 event.title作为字段名,但是它从未找到来自同一事件的任何文档。

When I am displaying a single document, I want to show "More like this" where more-like-this actually represents more documents from the same meeting, by the same author, or on the same topic. Author and Topic work fine, but although mlt_fields accepts "event.title" as a fieldname, it doesn't ever find any documents from the same event.

我的映射:

{
   "myindex": {
      "mappings": {
         "myitem": {
            "properties": {
               "authors": {
                  "type": "string",
                  "analyzer": "keyword"
               },
               "id": {
                  "type": "integer"
               },
               "title": {
                  "type": "string"
               },
               "topics": {
                  "type": "string",
                  "analyzer": "keyword"
               },
               "event": {
                  "type": "nested",
                  "properties": {
                     "title": {
                        "type": "string",
                        "analyzer": "keyword"
                     },
                     ...
                  }
               }
            }
         }
      }
   }
}

我的查询:

GET /myindex/mydoc/7/_mlt?mlt_fields=event.title&min_doc_freq=1&min_term_freq=1&percent_terms_to_match=0
{
  "from": 0,
  "size": 5
}

我的结果:

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

我怀疑这是一个嵌套的东西,所以我是否必须使用 event = my_event或更像该主题的 author或topic创建一个嵌套的过滤查询?还是我只是缺少一些真正愚蠢的东西?

I suspect this is a nesting thing, so do I have to create a nested filtered query with "event = my_event" OR more-like-this = "author or topic" ? Or am I just missing something really stupid ?

推荐答案

是的,您必须执行嵌套查询才能查询嵌套字段:

Yes, you have to do a nested query to query nested fields:


由于嵌套文档始终被父文档屏蔽,因此无法在嵌套查询范围之外访问嵌套文档。

Because nested docs are always masked to the parent doc, the nested docs can never be accessed outside the scope of the nested query.

http://www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/mapping-nested-type.html
http://www.elasticsearch.org/guide/ zh_CN / elasticsearch / reference / current / query-dsl-nested-query.html

这篇关于ElasticSearch More_Like_This API和嵌套对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆