Elasticsearch Java API Common Query method QueryBuilder Construction Example

Source: Internet
Author: User

Reprint: Http://m.blog.csdn.net/u012546526/article/details/74184769Elasticsearch Java API Common query Methods QueryBuilder Construction Example Environment Elasticsearch version

5.1.1

Pom
<Dependency>    <groupId>Org.elasticsearch</groupId>    <Artifactid>Elasticsearch</Artifactid>    <version>5.1.1</version></Dependency>

Elasticsearch Index Mode number
{    "type": "Long"}

String
{    "type": "Text",    "fields": {        "keyword": {            "type": "Keyword",            "Ignore_above":    []}}

Exact query

The following field names are replaced with ${fieldname}, and the values are replaced with ${fieldvalue}

Digital

Single

QueryBuilder QB1 = Querybuilders.termquery ("${fieldname}", "${fieldvalue}");

Batch

QueryBuilder QB1 = Querybuilders.termsquery ("${fieldname}", "${fieldvalues}");

String

Single

QueryBuilder QB1 = querybuilders.termquery ("${fieldname}.keyword", "${fieldvalue}");

Batch

QueryBuilder QB1 = querybuilders.termsquery ("${fieldname}.keyword", "${fieldvalues}");
Fuzzy query numbers

Numeric queries are exact queries

String
QueryBuilder QB1 = querybuilders.morelikethisquery (New string[]{"${fieldname}"}, New string[]{"${fieldvalue}"}, NULL) ;

Range Query Numbers

Closed interval Query

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). from (${fieldvalue1}). to (${fieldvalue2});

Open interval Query

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). from (${fieldvalue1}, False). to (${fieldvalue2}, False);

Greater than

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). GT (${fieldvalue});

 

Greater than or equal

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). GTE (${fieldvalue});

 

Less than

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). LT (${fieldvalue});

Less than or equal

QueryBuilder QB1 = Querybuilders.rangequery ("${fieldname}"). LTE (${fieldvalue});

 
Multi-Criteria Query
QueryBuilder QB1 = querybuilders.morelikethisquery (New string[]{"${fieldname1}"}, New string[]{"${fieldvalue1}"}, NULL); QueryBuilder QB2 = Querybuilders.rangequery ("${fieldname2}"). GT ("${fieldvalue2}"); QueryBuilder Qb3 = Querybuilders.boolquery (). Must (QB1). must (QB2);

Elasticsearch Java API Common Query method QueryBuilder Construction Example

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.