Control the returned fields values of a response


(Tomer Praizler) #1

Hi!

I have the following document:

{
   "name" : ["xxxx"],
   "data" : ["aaa|0.1", "bbb|0.2", "ccc|0.3", "ddd|0.4", "eee|0.5", "fff|0.6", "ggg|0.7", "hhh|0.8", "iii|0.9"],
}

I have 2 use cases:

  1. I want to control in the returned fields\ values, so I would like to get a response like this:

    {
    "hits" : {
    "tota l" : 1,
    "hits" : [ {
    "fields" : {
    "name" : [ "xxxx" ],
    "value" : [ 0.7 ]
    }
    } ]
    }
    }

Basically I want to retrieve the name field, and the payload of the "ggg" term in the "data" field.
2.

{
    "hits" : {
       "total" : 1,
       "hits" : [ {
       "fields" : {
          "name" : [ "xxxx" ],
           "value" : [ "ggg|0.7" ]
        }
     } ]
   }
}

Here I want to retrieve the name field, and the load only "ggg|0.7" term to the "data" field.

I saw that maybe I can achieve this with script_fields, is this the only option?
If it is, should it be a native script, or inline script?

Thanks!


(Adrien Grand) #2

script_fields might work but this looks to me like a very complex solution compared to just doing the processing on client side?


(Tomer Praizler) #3

The problem is that this field can contain 800K terms, meaning the response will be huge..
This is why I am doing the processing in Elasticsearch.


(system) #4