Get entity by its parent entity's value in Elasticsearch Get entity by its parent entity's value in Elasticsearch elasticsearch elasticsearch

Get entity by its parent entity's value in Elasticsearch


You should probably read this article: http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/ You're trying to apply RDBMS concepts to elasticsearch and that is usually a bad idea. Really, even if you are storing objects, they are still stored flat in elasticsearch behind the scenes.

I think this query will get you to where you want to be though, if I'm understanding you correctly:

{    "query": {        "bool": {            "must": [                {                    "term": {                        "username": "some matched item"                    }                },                {                    "filtered": {                        "filter": {                            "exists": { "field" : "address" }                        }                    }                }            ]        }    },    "fields": [        "address"    ]}

Does it matter if you extract the addresses or if you ask elasticsearch to do it for you? Sometimes you don't want to send all that data over the wire if not needed and that might be your reason.

This will still return something like this:

hits: [{_index: indexname_type: typename_id: id_score: 1.4142135fields: {address: [{someaddress_object}]}}, ...

So you will still need to loop through the results anyway when you get them back, just the result size is smaller.