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