Field aliases in search results

The field aliases in search results show the original field names and not aliases.

How do we get the alias field names in the search result.

Ex:

    PUT myindex
    {
      "mappings": {
          "properties": {
            "firstname": {
              "type": "text"
            },
            "fn": {
              "type": "alias",
              "path": "firstname" 
            }
        }
      }
    }

    POST myindex/_doc
    {
      "firstname": "hello"
    }

    GET myindex/_search
    {
      "query": {
        "match": {
          "fn": "hello"
        }
      }
    }

In the result we get the below output.

  {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 0.6931471,
        "hits" : [
          {
            "_index" : "myindex",
            "_type" : "_doc",
            "_id" : "uxp7vnIBJVpfmbc3lqnD",
            "_score" : 0.6931471,
            "_source" : {
              "firstname" : "hello"
            }
          }
        ]
      }
    }

How do we get a result like this:

  {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 0.6931471,
        "hits" : [
          {
            "_index" : "myindex",
            "_type" : "_doc",
            "_id" : "uxp7vnIBJVpfmbc3lqnD",
            "_score" : 0.6931471,
            "_source" : {
              "fn" : "hello"
            }
          }
        ]
      }
    }

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