Search result field name alias


#1

Hello,

I am looking for a way to have a query that returns the name of field differently. Like SQL's " SELECT column_name AS alias_name". Feel like there would be an easier solution but only I can think of is using a script to achieve this. For example,

  "script_fields" : {
    "alias_name" : {
      "script" : {
        "source" : "doc['column_name'].value",
        "lang" : "painless"
      }

And outcome,

 "_source":{
    "column_other1": "value1",
    "column_other2":"value2",
    .....
 },
 "fields":{
    "alias_name":[
      "value"

Is there a better solution than this? I concern performance using the script.
Thanks in advance,


(Andrei Stefan) #2

Hi @jimyoo,
Maybe field aliases? https://www.elastic.co/guide/en/elasticsearch/reference/6.4/alias.html


#3

Thanks Andrei for the information.

That seems a good solution for mapping statically. However, I wonder, instead, if we can do dynamically at the search time only.
Also even with "Alias datatype", alias names are not present in the document source I can't think of how that (alias) name can be shown in the search results. i.e., in "fields" or "_source".


(system) #4

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