【问题标题】:ElasticSearch More_Like_This API and Nested Object PropertiesElasticSearch More_Like_This API 和嵌套对象属性
【发布时间】:2015-03-13 17:26:49
【问题描述】:

我对 ES 还很陌生,如果这是我尚未发现的常见场景,请原谅我。

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

当我显示单个文档时,我想显示“更多类似”,其中“更多类似”实际上表示来自同一会议、同一作者或同一主题的更多文档。 Author 和 Topic 工作正常,但尽管 mlt_fields 接受“event.title”作为字段名,但它永远不会找到来自同一事件的任何文档。

我的映射:

{
   "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" OR more-like-this = "author or topic" 创建一个嵌套的过滤查询?还是我只是错过了一些非常愚蠢的东西?

【问题讨论】:

  • 遇到了类似的问题,你是怎么解决的?
  • 放弃了使用“more-like-this”的想法,只是做了一个单独的查询,从结果中排除了当前文档。
  • 这就是我所害怕的,该死的......我让所有东西都使用非嵌套,为了更好的性能和索引而移动到嵌套......真是遗憾。
  • 您可以将include_in_parent: true 属性添加到event 字段,以“展平”嵌套数据,同时拥有单独的文档。

标签: search elasticsearch


【解决方案1】:

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

因为嵌套文档总是被父文档屏蔽,嵌套文档永远无法在嵌套查询范围之外访问。

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

【讨论】:

  • 感谢您确认需要嵌套。那么,如何使用嵌套查询和“更像这样”来发出单个调用来过滤我的结果?还是“More like this 不支持嵌套对象,所以如果需要在嵌套对象字段上使用就不要使用”的情况
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
  • 2015-10-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 2012-11-12
相关资源
最近更新 更多