Elasticsearch _search-API _source alias

20 Views Asked by At

Is there a way to give a response field in an elasticsearch _search-query an alias like in database queries (select lastname as user from users)?

The result is consumed by a Java-Client, which I want to generate a report directly from the elasticsearch result without any mappings in the Java code. Are there any other ways of adjusting the result response?

For example:

This is my document:

{
   "id": 1,
   "lastname": "manchu"
   "firstname": "foo"
}

This is the search query:

GET {{url-elastic}}/{{index}}/_search
Content-Type: application/json
{
    "_source": ["lastname" as name]
}

And this is the desired response:

{
  "took": 3,
  ...
  "hits": {
    ...
    "hits": [
      {
        "_index": "1",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "id": 1,
          "name": "manchu",
          "firstname": "foo",
        }
      }
    ]
  }
}
0

There are 0 best solutions below