Best way to find the length of array in elasticsearch

> "asst_re": [
> {
> "rep_type": 345,
> "repo_id": 7144220
> }
> ,
> {
> "rep_type": 545,
> "repo_id": 7084555
> }]

I have to filter the "asst_re" array on the basis of length of the array.
What is the best and optimise way to do and achieve this thing in elasticsearch 6.2 ?
Thanks in Advance !!

best way: is to have the array length in another field at index-time
other way: do a script query (search for this has been done many times)

1 Like

@ddorian43 thanks for the answer !!!:+1:
I have one more query, what is the best way to count the number of words in a field ?
Ex - "name":"John doe bishop" , So the name field have 3 words, what should be the query for this type of filtering ?

the same as with array-length

Thanks @ddorian43 !!!
What is the query for that using script ? Can you help me out for this ?:grinning:

Sorry you gotta search for it. But that is SLOW!
Better to always store as separate field "array_length": 5

Agreed with @ddorian43

Specifically because you asked for:

What is the best and optimise way

@ddorian43 thanks for the justification !!:+1:
@dadoonet Yeah correct :grinning:

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