1

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 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Actually I want to do something blog.qbox.io/… this link . I made all analyzer ,ngram ve tokenizer defination. I successed to work this query with curl but I tried a lot of query type in java api and no solution.
Thanks for reply Tomek.The code in your edit works fine thanks a lot. Can you look at this question ? Nobody answered this stackoverflow.com/questions/25765465/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.