1
votes

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"
        }
          }
       }
}'
1

1 Answers

2
votes

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


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