Elasticsearch's Javaapi query dsl-queries
Like the rest query dsl ,elasticsearch provides a complete Java query DSL. The Query Builder (factory) is QueryBuilders
. Once you have your query ready , You can use the query API.
How to useQueryBuilders?仅仅就是加入下面的包:
Import org . Elasticsearch . Index . Query . querybuilders .*;
Note that you can easily print ( aka Debug ) The JSONgenerated by the query, using the toString()
method
Any API that can be used to accept queries , such as Count and. QueryBuilder
search)
The following examples illustrate several common query APIs:
Match Query
QueryBuilder=querybuilders. Matchquery ("name","Kimchy elasticsearch");
Multimatch Query
QueryBuilder=querybuilders. Multimatchquery ("Kimchy elasticsearch",//Text You is looking for "User","message"// fields );
Boolean Query
QueryBuilderQB= querybuilders .Boolquery() .must(Termquery("Content", "Test1")) .must(Termquery("Content", "Test4")) .Mustnot(Termquery("Content", "Test2")) .should(Termquery("Content", "Test3"));
Boosting Query
querybuilders.Boostingquery() .Positive(querybuilders.Termquery("Name","Kimchy")) .Negative(querybuilders.Termquery("Name","Dadoonet")) .Negativeboost(0.2f);
Range Query
QueryBuilderQB= querybuilders .Rangequery("Price") . from(5) . to(Ten) .Includelower(true) .Includeupper(false);
QueryString Query
QueryBuilder=querybuilders. queryString ("+kimchy-elasticsearch");
Term Query
QueryBuilder=querybuilders. Termquery ("name","Kimchy");
More like this (Field) Query (MLT and Mlt_field)//MLT Queryquerybuilders.Morelikethisquery("Name.first", "Name.last") // fields .Liketext("text like this one") //Text .Mintermfreq(1) //Ignore Threshold .maxqueryterms( A); //Max num of Terms //In generated queries//Mlt_field Queryquerybuilders.Morelikethisfieldquery("Name.first") // only in single field .Liketext("text like this one") .Mintermfreq(1) .maxqueryterms( A);
Elasticsearch's Javaapi query dsl-queries