How to filter by external data not indexed in ElasticSearch How to filter by external data not indexed in ElasticSearch elasticsearch elasticsearch

How to filter by external data not indexed in ElasticSearch


Seems a good fit for a parent child relation between players and items, even if you don't need full text search on the parent documents, because:

  1. each item belongs to a player
  2. they have independent update lifecycles: when a player changes, you don't want to reindex all his items
  3. you only want to return the children, applying a filter to their parents.

You could index your players too, in the same index as the items but within a separate type. You need to declare in your mapping that the player type is parent of the item type:

{  "item":{    "_parent":{      "type" : "player"    }  }}

After that you index the players, then your items specifying the parent player id for each of them.

You can then execute a full text search on the items, filtering them using the following has_parent filter.

{    "has_parent" : {        "parent_type" : "player",        "query" : {            "term" : {                "status" : true            }        }    }}

This way you would only query and eventually return the items that belong to an active player.

In order to update players you can use the update API and maybe use scripting to avoid resending the whole document. Beware that the document is going to be deleted and reindexed anyway under the hood, that's how lucene works.

If you want to see more examples about relations between documents in elasticsearch, have a look at the following articles:

Depending on the type of queries that you are going to need you might encounter limitations, but given what you've written this is what I would do. Just make sure your nodes have enough memory, since elasticsearch keeps in memory a join table containing all the ids involved when using parent-child.