Ниже приведены данные в es
"id":1, "platform":"sougou_wechat", "screen_name":"aaa", "created_at":1530028800000
"id":2, "platform":"sougou_wechat", "screen_name":"bbb", "created_at":1530028800000
"id":3, "platform":"sougou_wechat", "screen_name":"ccc", "created_at":1530028800000
"id":4, "platform":"sougou_wechat", "screen_name":"aaa", "created_at":1529942400000
Теперь я хочу удалить записи screen_name в [aaa, bbb]
curl -XGET '127.0.0.1:9200/test/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": { "bool": {"must" : [{"match":{"platform":"sougou_wechat"}}] , "filter" : { "terms" : { "screen_name" : ["aaa", "bbb"] } }, "filter":[{"range":{"created_at":{"gte":1530028800000,"lt":1530115200000} }}] } }
}
'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "test",
"_type" : "foo",
"_id" : "2",
"_score" : 0.2876821,
"_source" : {
"id" : 2,
"platform" : "sougou_wechat",
"screen_name" : "bbb",
"created_at" : 1530028800000
}
},
{
"_index" : "test",
"_type" : "foo",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"id" : 1,
"platform" : "sougou_wechat",
"screen_name" : "aaa",
"created_at" : 1530028800000
}
}
]
}
}
действительно возвращает two
записей, которые я хочу удалить, но когда я выполняю delete_by_query
, используя тот же запрос, почему three
записи удаляются? кажется, что второй фильтр не работает, потому что осталась только четвертая запись.
➜ ~ curl -X POST "127.0.0.1:9200/test/_delete_by_query?pretty" -H 'Content-Type: application/json' -d'
quote> {
quote> "query": { "bool": {"must" : [{"match":{"platform":"sougou_wechat"}}] , "filter" : { "terms" : { "screen_name" : ["aaa", "bbb"] } }, "filter":[{"range":{"created_at":{"gte":1530028800000,"lt":1530115200000} }}] } }
quote> }
quote> '
{
"took" : 210,
"timed_out" : false,
"total" : 3,
"deleted" : 3,
"batches" : 1,
"version_conflicts" : 0,
"noops" : 0,
"retries" : {
"bulk" : 0,
"search" : 0
},
"throttled_millis" : 0,
"requests_per_second" : -1.0,
"throttled_until_millis" : 0,
"failures" : [ ]
}
p.s. Приведенный ниже запрос может правильно удалить две записи
"query": {
"bool": {
"must": [{
"match": {
"platform": "sougou_wechat"
}
}, {
"terms": {
"screen_name": ["aaa", "bbb"]
}
}, {
"range": {
"created_at": {
"gte": 1530028800000,
"lt": 1530115200000
}
}
}]
}
}
p.s.
➜ ~ curl 'http://192.168.0.25:9200/test/_validate/query?explain=true&pretty' -H 'Content-Type: application/json' -d'
quote> {
quote> "query": { "bool": {"must" : [{"match":{"platform":"sougou_wechat"}}] , "filter" : { "terms" : { "screen_name" : ["aaa", "bbb"] } }, "filter":[{"range":{"created_at":{"gte":1530028800000,"lt":1530115200000} }}] } }
quote> }
quote> '
{
"valid" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [
{
"index" : "test",
"valid" : true,
"explanation" : "+platform:sougou_wechat #screen_name:aaa screen_name:bbb #created_at:[1530028800000 TO 1530115199999]"
}
]
}
и версия, которую я использовал
"version" : {
"number" : "5.5.2",
"build_hash" : "b2f0c09",
"build_date" : "2017-08-14T12:33:14.154Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},