Is it possible to access to a different document by ID in script?

Dear friends,

Assume I have three documents in three indexes referencing each other through some attributes:

{
  "_index": "a",
  "_id": "a:0",
  "_source": {
    "child": "b:0"
  }
}

{
  "_index": "b",
  "_id": "b:0",
  "_source": {
    "child": "c:0",
    "parent": "a:0"
  }
}

{
  "_index": "c",
  "_id": "c:0",
  "_source": {
    "parent": "b:0"
  }
}

I wanted to perform a query to get all documents from index c whose "grand parent" is document "a:0". Unfortunately I cannot find out the way to do it in one query, so I have to query for documents whose parent is "a:0" from index b, and then query for documents from index c with the previous result as a filter.

To improve performance, it seems I have to insert "grand parent" document IDs to the documents in index c as well, then I just need to query once. In fact my index is quite large already, so I would prefer to insert this new field into the documents instead of reindexing everything. To do this I need to access to both indexes b and c, so that for each document in c I get parent document ID, and access to this document through ID index b to get "grand parent" document ID. However I also didn't find any example from the Web moving towards this direction.

I am not sure if I have explained my problem clearly. Is such solution really possible?

Any help is highly appreciated.

Best regards,
Yang

scripts cannot do further look ups to other documents. You would need to solve this issue at index time.

A look at the join datatype might help, but please take your time to properly read the documentation about it, as it comes with some limitations.

--Alex

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