Elasticsearch 有嵌套文档(很棒)。我想用它来存储消息(顶级文档)及其作者(嵌套文档)。
由于一个作者可以有许多消息——可以将作者的一个版本作为多个消息的子级引用吗?
这样,如果您在一个地方更新作者数据,它会在所有引用它们的地方更新。
注意:这与:如何在 Elasticsearch 中或在 Lucene 级别进行连接- 这里的答案也可能解决这个问题。
Elasticsearch 有嵌套文档(很棒)。我想用它来存储消息(顶级文档)及其作者(嵌套文档)。
由于一个作者可以有许多消息——可以将作者的一个版本作为多个消息的子级引用吗?
这样,如果您在一个地方更新作者数据,它会在所有引用它们的地方更新。
注意:这与:如何在 Elasticsearch 中或在 Lucene 级别进行连接- 这里的答案也可能解决这个问题。
You may want to take a look using a _parent
mapping: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-parent-field.html
This allows you to create a type for an Author and a separate type for a Message (with _parent type of Author), then index documents separately and add to the messages over time. You only need to update the single version of an Author for it to affect queries for all messages with that Author.
To achieve queries of messages with a specific author you'll need to use the has_parent query or filter. Or the reverse, use has_child to find authors with certain messages.
I have been using this more dynamic form rather than nested documents and it has worked well for me (for both queries and facets), but you must take care defining your mappings before loading any documents of that type, since adding the _parent
mapping after the fact doesn't seem to work for me. And reindexing has been something I have failed to manage so far.