Find length of array in that doc

(LogSpree) #1

I have a field in my index which is an integer array. I want to add another field which contains the count of the number of elements.

Even an API call that gives the count is fine.

I have found something relevant :
"script" : "doc['MyField'].values.size()"

But I don't know how & where to use it.
Please help!

(Val Crettaz) #2

I didn't see you cross-posted this, but here is your answer

Hope it helps :wink:

(LogSpree) #3

Thanks :smile: @val

Could you plz explain "ctx"?

Also, is there a way to do this in the logstash config? It would save time in large file size. Because I'm getting a "gateway timeout" in case of actual 22GB data.

(Val Crettaz) #4

I'm not sure how Logstash would help in this case. Update by query can only be called via the REST API or through a client library.

Also note that Gateway timeout doesn't mean that the task is killed, just that your client connection has timed out, but the task is still ongoing in the background. If you run the command below, you'll see that the update is still running:

GET _tasks?actions=*byquery&detailed=true

(system) #5

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