Elasticsearch条件query

按照时间升序降序query

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def query_byid(self, id, size, reverse_order=False):
if reverse_order == True:
_order = 'desc'
else:
_order = 'asc'
dsl = {
"query": {
"bool":{
"must": [
{"match":{"id":id}},
],
}
},
"sort": [
{ "service.data.time" : {"order" : _order}},
"_score"
],
"_source": [
"service.data",
"deviceId"
],
"size":size,
}
raw_data = self.query(dsl)
raw_list = raw_data["hits"]["hits"]
return raw_list