0

I have Elasticsearch documents which looks like below :

MetaData metadata,
... many other properties...

MetaData class :

public class MetaData {
private List<String> keywords;
}

Now I want to build a query which match the provided string to the metadata.keywords's 0 index.

Code example : metadata.keywords[0] equals to input string

What I have done is below :

BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.existsQuery("metadata.keywords"));

How can I specify the index to do the same?

1 Answer 1

0

For Elasticsearch, arrays are like multivalue fields where the order of the values is not relevant, so there is no explicit search on an index position like [0].

You might check this answer (Elasticsearch query on array index) if this approach works for you (try the query out manually with some REST client). If it does, you will need to build the query with this filters using the NativeSearchQueryBuilder from Spring Data Elasticsearch - although I cannot guarantee that all necessary operations are available.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.