Java-elasticsearch Query Type __java

Source: Internet
Author: User

Query type

QueryType

Description

Background code Sample

Matchallquery

Full match

QueryBuilder QB = Matchallquery ();

Matchquery

Single match

QueryBuilder QB = Matchquery (

"Name",

"Kimchy Elasticsearch"

);

Multimatchquery

Multi-field Single value matching

QueryBuilder QB = Multimatchquery (

"Kimchy Elasticsearch",

"User", "message"

);

Wildcardquery

Fuzzy matching

Wildcardquerybuilder queryBuilder1 = querybuilders.wildcardquery ("EmpName", "*emp*");


Compound query Type

Booltype

Description

Background code Sample

and

And

Boolquerybuilder subcodequery = Querybuilders.boolquery ();

Wildcardquerybuilder queryBuilder1 = querybuilders.wildcardquery ("EmpName", "*emp*");

Wildcardquerybuilder queryBuilder2 = querybuilders.wildcardquery ("Gender", "*male*");

Subcodequery.must (QueryBuilder1);

Subcodequery.must (QUERYBUILDER2);

OR

Or

Similar (subcodequery.should)


Paging
Pagination is done through the From and size parameters. From defines the starting position of the query result, the size definition returns the maximum number of hits (a hit corresponding to one record).

RESTful sample

Background code example

{

    "from": 0, "size": Ten,

    "query": {

  &N bsp;     "term": {"user": "Kimchy"}

   }

}

Searc Hresponse response = Client.preparesearch ("dept")

                 settypes ("employee")

                 setquery (QueryBuilder)

                 setfrom (0). SetSize (2)

                 execute ()

                 Actionget ();



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.