简体   繁体   English

将嵌套文档链接在一起并在ElasticSearch中进行构面

[英]Linking nested documents together and facetting in ElasticSearch

I have a mapping which looks like this: 我有一个看起来像这样的映射:

"mappings": {
    "mydoc": {
        "properties": {
            "event": {
                "type": "nested",
                "properties": {
                    "eventType": {
                        "type": "string"
                    },
                    "idList": {
                        "type": "integer"
                    },
                    "id": {
                        "type": "integer"
                    },
                }
            }
        }
    }
}

A mydoc document contains a nested array of event documents. Mydoc文档包含事件文档的嵌套数组。

Within a mydoc document, I want to find all IDs where: 在mydoc文档中,我想在以下位置找到所有ID:

  • There exists an event with event.type='A' and event.idList contains some ID X 存在一个带有event.type ='A'的事件,并且event.idList包含一些ID X
  • There exists another event with event.type='B' and event.id equals X 存在另一个event.type ='B'并且event.id等于X的事件

Across the index, I want a list of IDs where this criteria holds and also a count (for each ID) of the number of mydoc documents this occurred in. 在整个索引中,我想要一个包含此条件的ID列表,以及一个出现此ID的mydoc文档数量的计数(每个ID)。

Is it possible to achieve this in ElasticSearch? 是否可以在ElasticSearch中实现这一目标? I was thinking it might be possible with a nested facet filter or a terms filter lookup but I have not seen a way to do it with these yet. 我当时想使用嵌套的构面过滤器或术语过滤器查找是可能的,但是我还没有找到一种使用这些方法的方法。

I think that a parent-child relation might suit your case better then a nested document. 我认为,父子关系可能比嵌套文档更适合您的情况。
Then you can query you (child) events document directly if you're searching only in the scope of the events (or add a condition on the _parent field to limit to a specific top document). 然后,如果您仅在事件范围内进行搜索,则可以直接查询您(子)事件文档(或在_parent字段上添加条件以限制到特定的顶部文档)。
And you can use the has_child filter or query to search (or facet) on your top documents with conditions on the events (see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html ) 而且,您可以使用has_child过滤器或查询来搜索(或分析)具有事件条件的顶级文档(请参阅http://www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/query-dsl- has-child-filter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM