Haktan Aydın
Haktan Aydın

Reputation: 591

Elastic Search Query with Java Api

I'm developing JSF project and using Elastic Search with native Java Api(not Jest). I defined analyzer and nGram filter for advanced full text search in elasticsearch index mapping. How can do this Query defination with java api ?

curl -XPOST "http://localhost:9200/blurays/_search?pretty" -d'
{
"size": 10,
"query":{
"match":  {
"_all": {
"query": "yellow bird",
"operator": "and"
        }
          }
       }
}'

Upvotes: 1

Views: 10825

Answers (1)

Tomek
Tomek

Reputation: 543

I'm not sure of your intention, but if you want to create an "and"/"or" queries try something like this:

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); 

and for example:

boolQueryBuilder.must(QueryBuilders.matchQuery(field, value));

You can add as many queries (any type - multiMatch, term etc.) as you want. Try also try should() or mustNot() methods - depends of what do you want.

Here is a more complex example: http://massapi.com/class/bo/BoolQueryBuilder.html


EDIT: Thanks for comment, now I think I'm understand. Something like below?

QueryBuilders.matchQuery(field, value).operator(MatchQueryBuilder.Operator.OR);

Upvotes: 2

Related Questions