1 must嵌套should条件查询
代码语言:javascript复制curl -XGET 'xxx/xxx/_search?pretty' -H 'Content-Type: application/json' -d'{
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"uisendtime": {
"gte": 1506535200,
"lte": 1506607200
}
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"strtitle.infosec": "两清"
}
},
{
"match_phrase": {
"strdescription.infosec": "两清"
}
}
]
}
}
]
}
}
}'
注意: 1)如果must或者should中用到多个条件,每个条件必须用大括号括起来,嵌套的bool查询必须从新指定bool
2 先过来后聚合,然后对聚合出的数据求top然后按照某属性的最大值排序
代码语言:javascript复制curl -XGET 'http://xxx/xxx/_search?pretty' -d '
{
"query": {
"bool": {
"must": [
{
"match": {
"strcommocrtxtcont": {
"query": "福利",
"type": "phrase"
}
}
}
]
}
},
"aggs": {
"md5_distinct_count": {
"cardinality": {
"field": "strpicdownloadimgmd5"
}
},
"top_tags": {
"terms": {
"field": "strpicdownloadimgmd5",
"order": {
"max_uisendtime": "desc"
},
"size": 10
},
"aggs": {
"top_url_hits": {
"top_hits": {
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"size": 1
}
},
"max_uisendtime": {
"max": {
"field": "uisendtime"
}
}
}
}
},
"size": 0
}'
注意:top_tags的属性strpicdownloadimgmd5是按照max_uisendtime排序的,而max_uisendtime(求出top_hits中uisendtime的最大值)是你自己在一个聚合中定义的。
3 查出的数据中过滤长度为0的字符串
代码语言:javascript复制curl xxx/xxx/_search?pretty -d'{
"size": 5,
"_source": [
"strdescription",
"uisendtime",
"strtitle"
],
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"strtitle": "u738bu8005"
}
},
{
"match_phrase": {
"strtitle": "u8363u8000"
}
}
]
}
}
],
"must_not": [
{
"script": {
"script": {
"inline": "params._source.strdescription.length() < 1"
}
}
}
]
}
}
}'
注意:params._source.strdescription.length() < 1 可用 d oc[u0027strdescriptionu0027].length()<1 或者doc['''strdescription''']<1代替。