Careful when using a repeated array of objects
"One of the problems when indexing inner objects that occur several
times in a doc is that “cross object” search match will occur, for example:"
To use the following user with comments example, in the above warning
"several times", might be an array of comments.
If you want to find any user who has any comment with some terms in the
body, no problem, but if you want to find any user who has a comment of
type = 2 and that comment has a body that contains some terms, you might
get false positives when there is a comment of type 2 and there is a
comment with the terms, but not necessarily the same comment.
If you want to filter on comments.type and search on comments.body,
you'd want to use an inner object of type nested, or get more complex
and use child docs.
If the comments come along after the user and have a different
life-cycle, child comments might be just the thing, but you can't obtain
child values when you obtain user values, so you'd have to go back for
another search. Searching documents is not like doing SQL in a database.
On 9/28/2012 9:52 AM, es_learner wrote:
I have a similar schema and to the best of my knowledge, array(or list in my
Python/pyes case) is the way to model the 1-to-many relationship.
In my client code, I populate the 'comments' list for each user where each
comment is a python dict(keys: id, body)
e.g. query syntax: curl
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/How-to-model-this-relationship-in-ES-tp4023306p4023332.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.