Bool query is used to combine default queries for multiple leaf or compound query clauses
Must equivalent to & =
Must not equal to ~! =
should equivalent to or | Or
Filter filters
Boolquery () . Must(termquery ("Content", "test1"))
. must (Termquery ("Content", "test4"))
. Mustnot (Termquery ("Content", "test2"))
. should (Termquery ("Content", "test3"))
. Filter (Termquery ("Content", "test5"));
Private SearchRequest Getsearchrequest (RequestType request) {
searchrequest sr = new SearchRequest ();
Specifies the index name, if unspecified, to query all
Sr.indices (Elasticsearchconst.xxx_index);
Sr.types (Elasticsearchconst.xxx_type);
Searchsourcebuilder Source = new Searchsourcebuilder ();
Boolquerybuilder BQ = Querybuilders.boolquery ();
Getquerybuilder (request, BQ);
From 0 onwards, including front and back boundaries is actually <= >=
Source.from (Request.getrowstart ());
Source.size (Request.getrowsize ());
Source.query (BQ);
Setsort (request, source);
Sr.source (source);
return SR;
}
private void Getquerybuilder (RequestType request, Boolquerybuilder Bq) {
Getorderquerybuilder (request, BQ);
Addpurchaseorderquerybuilder (request, BQ);
}
/**
* Query conditions
*
* @param request
* @param BQ
*/
private void Getorderquerybuilder (RequestType request, Boolquerybuilder Bq) {
Termquery exact match, no participle equals =
Type.childtype Multilayer type nesting, specific index structure, reference mapping
GET yourindexname/_mapping
Mapping:
{
"Yourindexname": {
"Mappings": {
"Type1": {
"Properties": {
"Childtype": {
"Properties": {
"Cedstatus": {
"Type": "Text",
"Fields": {
"keyword": {
"Type": "Keyword",
"Ignore_above": 256
}
}
},
Bq. must (querybuilders.termquery("type.childtype", Request.getorderid ()));
Rangequery range query, maximum range not exceeding 1w
Bq.must (querybuilders.rangequery("type.childtype. Departuredate")
. GTE (Dateutil.tosqltimestamp (Request.getdeparturedatestart (). GetTime ()). GetTime ())
. LTE (Dateutil.tosqltimestamp (Request.getdeparturedateend (). GetTime ()). GetTime ());
querybuilders.matchphrasequery Matching query, no participle, equivalent to contains
Matchphrasequery is directly in the form of a phrase query, the order is not bad, and connected together
Pobq.must (querybuilders.matchphrasequery(
String.Format ("%s%s%s", PreFix, I, ". Vacationvbkpurchaseorderbaseinfodto.contactname"),
Request.getcontactname ()));
ElasticSearch (12) Bool Query JAVA API