Elasticsearch's Javaapi query dsl-queries

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.