原始脚本:
GET /logstash-jsy/nginx-access/_search
{
"size": 0,
"query": {
"bool": {
"should": [
{
"match_phrase": {
"req_url": "/account/login"
}
},
{
"match_phrase": {
"req_url": "/account/register"
}
}
]
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "@timestamp",
"interval": "6h",
"format": "yyyy-MM-dd-HH"
}
}
}
}
结果:
3w多条数据
增加条件
GET /logstash-jsy/nginx-access/_search
{
"size": 0,
"query": {
"bool": {
"should": [
{
"match_phrase": {
"req_url": "/account/login"
}
},
{
"match_phrase": {
"req_url": "/account/register"
}
}
],
"must": [
{
"geoip.city_name": "Shenzhen,Beijing"
}
}
]
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "@timestamp",
"interval": "6h",
"format": "yyyy-MM-dd-HH"
}
}
}
}
query部分增加了一个 must 条件,
结果:
结果反而变成了70多万,
希望结果是增加一个城市的条件后, 结果应该比3w多小,
请问问题出在什么地方, 应该如何修改?
GET /logstash-jsy/nginx-access/_search
{
"size": 0,
"query": {
"bool": {
"should": [
{
"match_phrase": {
"req_url": "/account/login"
}
},
{
"match_phrase": {
"req_url": "/account/register"
}
}
]
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "@timestamp",
"interval": "6h",
"format": "yyyy-MM-dd-HH"
}
}
}
}
结果:
3w多条数据
增加条件
GET /logstash-jsy/nginx-access/_search
{
"size": 0,
"query": {
"bool": {
"should": [
{
"match_phrase": {
"req_url": "/account/login"
}
},
{
"match_phrase": {
"req_url": "/account/register"
}
}
],
"must": [
{
- "match": {
"geoip.city_name": "Shenzhen,Beijing"
}
}
]
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "@timestamp",
"interval": "6h",
"format": "yyyy-MM-dd-HH"
}
}
}
}
query部分增加了一个 must 条件,
结果:
结果反而变成了70多万,
希望结果是增加一个城市的条件后, 结果应该比3w多小,
请问问题出在什么地方, 应该如何修改?
2 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: clean
{
"query": {
"bool": {
"must": [
{
"term": {"shape": "round"},
"bool": {
"should": [
{"term": {"color": "red"}},
{"term": {"color": "blue"}}
]
}
}
]
}
}
}
参考一下
clean
赞同来自:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"req_url": "/account/login"
}
},
{
"match_phrase": {
"req_url": "/account/register"
}
}
]
}
},
{
"match": {
"geoip.city_name": "Beijing"
}
}
]
}
},
"aggs": {
"sales": {
"date_histogram": {
"field": "@timestamp",
"interval": "6h",
"format": "yyyy-MM-dd-HH"
}
}
}
}
这样解决的