Filtering nested documents

Hello,
i have this data (simplified):

{
  id: 1,
  subs: [
    {
      date: "DUMMY_DATE_YESTERDAY"
    },{
      date: "DUMMY_DATE_TODAY"
    },{
      date: "DUMMY_DATE_TOMORROW"
    }
  ]
}

Is it possible to create a query, that will query:

id=1 and only show the "subs" where date >= today ?

Hope this makes sense.

I have tried to look into nested query and nester filter, but as i read it, it will "only" query nested as a document, but still return the parent doc, if matched.

So the question you are asking to elasticsearch is "can you search for subs"?
In that case, why not indexing subs?

Like:

PUT subs/doc/1
{
  "id": 1,
  "date": "DUMMY_DATE_YESTERDAY"
}
PUT subs/doc/2
{
  "id": 2,
  "date": "DUMMY_DATE_TODAY"
}

...

Hello David,
no my question is:

Can i query the "document" by id = 1, and then i will get:

{ 
  id: 1, 
  subs: [ 
    { date: "DUMMY_DATE_YESTERDAY" },
    { date: "DUMMY_DATE_TODAY" },
    { date: "DUMMY_DATE_TOMORROW" }
  ]
}

But instead of looping all the subs afterwards, i will also "filter/query" the subs.
As i said, i have simplified the dataset, i have data "outside" subs, that i also need.

So instead of this the data above, i would "like" if i could get this:

{ 
  id: 1, 
  subs: [ 
    { date: "DUMMY_DATE_TODAY" },
    { date: "DUMMY_DATE_TOMORROW" }
  ]
}

Cause they "match" id=1 and date >= TODAY

I understood your question.

I was just telling you that may be the way you are modelling your data might be incorrect.

But, if you really want to do it your way, may be inner hits could help: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-request-inner-hits.html

Hello David,
it is not my data. :slightly_smiling_face:
I'm just tried to access some data through the rest api.
So i cant change the data.
The data is the way it is.

And the data is running on ES 1.7.6

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