Need inverted nested mapping

How do I get search results that have the nested relationships inverted? Do I need to create another index with the nested relationships inverted? Or can I do this in another way with a different type of query and/or modifying the current index?

e.g. our index:

Doc1:
  id: 1
  someText: "a"
  someField1: [val1:{somefield2: "1"}, val2: {somefield2: "2"}, val3: {somefield2: "3"}]
Doc2:
  id: 2
  someText: "a"
  someField1: [val1:{somefield2: "1"}]
Doc3:
  id: 3
  someText: ""
  someField1: []

If I search for someText="a", we get the document ID's of Doc1,Doc2 (1,2), and then query postgres, our consistent data store, for subfields.

However, now I want to search for someText="a" and instead of getting the document ID's, I want to get all the val's associated with those docs, which are val1, val2, val3.

e.g. search for someText = "a" should return:

val1:
  doc1, doc2
val2:
  doc1

Should I create another index with this relationship inverted? The index would be:

val1:
  {somefield2: "1"}
  [doc1:  {someText: "a"}, doc2:  {someText: "a"}]
val2:
  {somefield2: "2"}
  [doc1: {someText: "a"}]
val3:
  {somefield2: "3"}
  [doc1: {someText: ""}]

Would something like a reverse nested aggregation work?

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