0

do you know if it's possible to transofrm a document at query time in Elastic Search?

Let's do and example.

I index a document like this

{
    "firstName": "John",
    "lastName": "Doe",
    "age": 35,
    "trips": [{
        "city": "NYC",
        "country": "USA"
    },
    {
        "city": "Chicago",
        "country": "USA"
    },
    {
        "city": "Rome",
        "country": "Italy"
    }]
}

and I would like to create a query that filter the documents by trips.country equals to USA and the returning document should be a transformation of the indexed document like this

{
    "firstName": "John",
    "lastName": "Doe",
    "trips": [{
        "city": "NYC",
        "country": "USA"
    },
    {
        "city": "Chicago",
        "country": "USA"
    }]
}

I know I can filter the _source field specifying the fields to return, but this is a case of a transformation of the _source because in my example I want the field trips.* but with only those subdocuments with country equals to USA

I can't transform it after elastic returns it because we should have to create query to pass to external systems that allow those systems to access directly elastic raw documents and return only the portion of data we want. The queries will be secured by shield.

In a few words we need to transform a document at query time

Thank you

Simone Belia
  • 253
  • 3
  • 10
  • Have you tried to use source filtering in the context of [nested `inner_hits`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-inner-hits)? – Val Jan 10 '17 at 14:01
  • you coudln't achieve it, if you're using nested documents, you could only get it, if you're using parent child docs – Mysterion Jan 10 '17 at 14:06

0 Answers0