How to effectively filter results based on another query (SQL JOIN -alike) against another type?


(Ville Mattila) #1

I have two different types in my index, representing the same entity but containing different body. Documents share the same ID.

Type event is similar to { "_id": "event1", "title": "Ville's Event", "date": "2017-04-30" }
Type event_interaction_stats is similar to { "_id": "event1", "likes_count": 10, "shares_count": 6}

The documents are splitted for performance purposes and obviously the above document examples are simplified.

Now I should be able to query all events that happen today and have more than 10 likes. I do currently first query event_interaction_stats, fetch list of ids and then do another query to event and in addition to date range, pass also list of id's that are allowed. This requires apparently two roundtrips to the server and the list of event ids from the first query can be large. Therefore I would prefer some other approach where both queries would be executed inside ElasticSearch and only final results would be returned to the application.

How could I accomplish this kind of behavior, or can I?


(Christian Dahlqvist) #2

Have you considered using a parent-child relationship here?


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.