java - How to build a query which matches one of the phrases in Spring Elasticsearch repository -
i know if , how possible create query matches 1 of keyword phrases , not contain of stop word phrases. example:
list<string> keywords = arrays.aslist("one keyword", "another one"); list<string> stopwords = arrays.aslist("dismiss this"); page<result> results = elrepository.findbykeywordsandstepwords( keywords, stopwords, new pagerequest(0, 12));
this should match documents containing 1 of exact phrases ("one keyword" or "another one") , no stop word phrases ("dismiss this"). note if document contains terms contained in phrases (eg. "another"), should not return given document result.
after long research, way achieve goal. hope someone:
boolquerybuilder keywordbuilder = boolquery(); keywords.foreach(k -> keywordbuilder.should(matchphrasequery("text", k))); boolquerybuilder stopwordbuilder = boolquery(); stopwords.foreach(s -> stopwordbuilder.should(matchphrasequery("text", s))); boolquerybuilder querybuilder = boolquery() .must(keywordbuilder) .mustnot(stopwordbuilder); page<result> results= elrepository.search(querybuilder, pageable);
Comments
Post a Comment