Search Query on ES JAVA API


(samCougars) #1

I'm using ES JAVA API. I am trying to do a search for exact match, like my search query will be Honda "yellow car". So my search result should be return all cars with Honda as a model or cars with "yellow car" (a single phrase) with car description.
At the moment, I am using BooleanQueryBuilder. How can I add "yellow car" on my queryBuilder?
Thanks


(Drew Raines) #2

samCougars wrote:

I'm using ES JAVA API. I am trying to do a search for exact match, like my
search query will be Honda "yellow car". So my search result should be
return all cars with Honda as a model or cars with "yellow car" (a single
phrase) with car description.
At the moment, I am using BooleanQueryBuilder. How can I add "yellow car" on
my queryBuilder?

Try something like this:

import static org.elasticsearch.index.query.QueryBuilders.*;

BoolQueryBuilder bool = new boolQuery()
  .should(termQuery("model", "honda"))
  .should(textPhraseQuery("yellow car"));

client().prepareSearch().setQuery(bool).execute().actionGet();

-Drew


(samCougars) #3

I ended up using "QueryBuilders.textPhrasePrefixQuery("description", "yellow car")" which did exact match on "yellow car"


(system) #4