Import only arrays that match conditions in Elastic Search

I'm dealing with nested nested data in ElasticSearch.

I want it to work like a SELECT * from where in an RDBMS.

If you have the following data

POST test-stack/test/1234_5678
{
  "Id" : 1234,
  "availables":[
    {
      "Id" : 4444,
      "date" : "2019-09-10",
      "time" : [
        {
          "dateTime" : "2019-09-10T09:30:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-10T10:00:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-10T10:30:00+09:00",
          "Count" : 50
        }
      ]
    },
    {
      "Id" : 5555,
      "date" : "2019-09-11",
      "time" : [
        {
          "dateTime" : "2019-09-11T09:30:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-11T10:00:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-11T10:30:00+09:00",
          "Count" : 50
        }
      ]
    },
    {
      "Id" : 6666,
      "date" : "2019-09-12",
      "time" : [
        {
          "dateTime" : "2019-09-12T09:30:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-12T10:00:00+09:00",
          "Count" : 50
        },
        {
          "dateTime" : "2019-09-12T10:30:00+09:00",
          "Count" : 50
        }
      ]
    }
  ]
}

If I do this,

Select * from test t where t.availables.date = '2019-09-10';

So, I want to get this answer,

  "Id" : 4444,
  "date" : "2019-09-10",
  "time" : [
    {
      "dateTime" : "2019-09-10T09:30:00+09:00",
      "Count" : 50
    },
    {
      "dateTime" : "2019-09-10T10:00:00+09:00",
      "Count" : 50
    },
    {
      "dateTime" : "2019-09-10T10:30:00+09:00",
      "Count" : 50
    }
  ]

I'm a beginner in Elastic Search and I wonder if this is possible in Elastic Search.

I've studied painless scripts but still don't know.

Take a look at the nested datatype as well as inner_hits

1 Like

Thank you so much!!! It is what I was looking for!

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