How to search data's prefix from array in Elasticsearch?
Asked Answered
C

1

6

Here I have several documents storaged in Elasticsearch.

document_example: { "data": ["red","brown", "black"] }

When I use prefix search(see below) to check whether there are some items in the array 'data' with prefix 'b', the result comes out with null while the document_example exists in Elasticsearch.

It seems that prefix search can be used for string, however excluded items in array.

{"query": 
    {
      "prefix": { "data" : "b" }
    }
}

So if I wanna find the data's prefix in array, how should I search in Elasticsearch? Thanks.

Culture answered 5/9, 2017 at 11:9 Comment(0)
H
-1

You just use a wildcard in your query; this is shown in the vendor docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html

Hilbert answered 5/9, 2017 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.