本文将演示如何使用ES提供的Java高级包来查询数据,首先API其实就是在底层构建一条DSL查询语句,所以我们首先看一下这条语句:
GET test*/_search
{
"timeout": "60s",
"query": {
"bool": {
"must": [
{
"terms": {
"status.keyword": [
"301",
"302"
],
"boost": 1
}
},
{
"match_phrase": {
"args": {
"query": "786754748671257",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"range": {
"@timestamp": {
"from": "2020-05-20T16:00:00.000Z",
"to": "2020-05-21T16:00:00.000Z",
"include_lower": true,
"include_upper": false,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"track_total_hits": 2147483647
}
接下来代码里的绑定查询条件部分都是围绕这条语句来写的
一 maven依赖
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>