2016-12-26 1 views
1

12 월 1 일보다 낮은 날짜의 문서는 삭제하려고하지만 실제로 삭제되는 것처럼 보이지는 않습니다. 쿼리 삭제 작업이 작동하지 않습니다.

나는 쿼리 API에 의해 삭제를 사용하여 시도 :

curl -XPOST "http://localhost:9200/mediadata/events/_delete_by_query" -d' 
{ 
    "query": { 
    "range": { 
     "created_at": { 
     "lt": "2016-12-01 00:00:00" 
     } 
    } 
    } 
}' 

또는 구문 : 사전에

{"_index":"mediadata","_type":"events","_id":"_delete_by_query","_version":10,"_shards":{"total":3,"successful":2,"failed":0},"created":false} 

감사 :

curl -XDELETE 'http://localhost:9200/mediadata/events/_query' -d ... 

내가 이런 종류의 결과를 얻을 수 있습니다.

편집 :

{ 
    "mediadata": { 
     "mappings": { 
      "events": { 
       "properties": { 
        "channels": { 
         "properties": { 
          "kdata": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "mail": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "md5": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "mobile": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "ssp": { 
           "type": "string", 
           "index": "not_analyzed" 
          } 
         } 
        }, 
        "contents": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "created_at": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "editor": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "end": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "location": { 
         "type": "geo_point" 
        }, 
        "message": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "price": { 
         "type": "double" 
        }, 
        "quantity": { 
         "type": "long" 
        }, 
        "query": { 
         "properties": { 
          "bool": { 
           "properties": { 
            "filter": { 
             "properties": { 
              "range": { 
               "properties": { 
                "created_at": { 
                 "properties": { 
                  "lt": { 
                   "type": "string" 
                  } 
                 } 
                } 
               } 
              } 
             } 
            }, 
            "must": { 
             "properties": { 
              "match_all": { 
               "type": "object" 
              } 
             } 
            } 
           } 
          }, 
          "filtered": { 
           "properties": { 
            "filter": { 
             "properties": { 
              "range": { 
               "properties": { 
                "created_at": { 
                 "properties": { 
                  "lt": { 
                   "type": "string" 
                  } 
                 } 
                } 
               } 
              } 
             } 
            }, 
            "query": { 
             "properties": { 
              "match_all": { 
               "type": "object" 
              } 
             } 
            } 
           } 
          }, 
          "range": { 
           "properties": { 
            "created_at": { 
             "properties": { 
              "lt": { 
               "type": "string" 
              }, 
              "lte": { 
               "type": "string" 
              } 
             } 
            } 
           } 
          } 
         } 
        }, 
        "reference": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "source": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "start": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "type": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "updated_at": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        } 
       } 
      } 
     } 
    } 

} 
+0

사용중인 매핑을 공유하십시오. lf 필드가 Date로 매핑 되었습니까? –

+0

@FacundoLaRocca 매핑을 추가했습니다. 예 날짜 유형입니다. – azekirel555

+0

@ azekirel555 GET 쿼리로 결과를 얻습니까? I – Yeikel

답변

5

귀하의 구문은 참으로 올바른 : 여기에 매핑합니다. 버전 5.x에서 쿼리에 의한 삭제는 다음과 같습니다. 구문이 다른 곳에 당신이, 당신은 버전 2.x를 실행하는 것을 나는 가정한다 ES

{"_index":"mediadata","_type":"events","_id":"_delete_by_query","_version":10,"_shards":{"total":3,"successful":2,"failed":0},"created":false} 

에서 얻고있는 반응에 따라 이제

POST mediadata/events/_delete_by_query?conflicts=proceed 
{ 
    "query": { 
    "range": { 
     "created_at": { 
     "gt": "2016-11-02 00:00:00" 
     } 
    } 
    } 
} 

.

curl -XDELETE "http://localhost:9200/mediadata/events/_query" -d' 
{ 
    "query": { 
    "range": { 
     "created_at": { 
     "gt": "2016-11-02 00:00:00" 
     } 
    } 
    } 
}' 

응답은 다음과 같습니다 그런

plugin install delete-by-query 

당신이 그것을 실행의 요청에 의한 삭제를 2.x으로 버전에서 모든

첫째, 당신은 사용하여 설치해야하는 플러그인입니다 :

{ 
    "took": 0, 
    "timed_out": false, 
    "_indices": { 
    "_all": { 
     "found": 1, 
     "deleted": 1, 
     "missing": 0, 
     "failed": 0 
    }, 
    "mediadata": { 
     "found": 1, 
     "deleted": 1, 
     "missing": 0, 
     "failed": 0 
    } 
    }, 
    "failures": [] 
} 

전체 예 :

PUT mediadata 
{ 
    "mappings": { 
      "events": { 
       "properties": { 
        "channels": { 
         "properties": { 
          "kdata": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "mail": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "md5": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "mobile": { 
           "type": "string", 
           "index": "not_analyzed" 
          }, 
          "ssp": { 
           "type": "string", 
           "index": "not_analyzed" 
          } 
         } 
        }, 
        "contents": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "created_at": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "editor": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "end": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "location": { 
         "type": "geo_point" 
        }, 
        "message": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "price": { 
         "type": "double" 
        }, 
        "quantity": { 
         "type": "long" 
        }, 
        "query": { 
         "properties": { 
          "bool": { 
           "properties": { 
            "filter": { 
             "properties": { 
              "range": { 
               "properties": { 
                "created_at": { 
                 "properties": { 
                  "lt": { 
                   "type": "string" 
                  } 
                 } 
                } 
               } 
              } 
             } 
            }, 
            "must": { 
             "properties": { 
              "match_all": { 
               "type": "object" 
              } 
             } 
            } 
           } 
          }, 
          "filtered": { 
           "properties": { 
            "filter": { 
             "properties": { 
              "range": { 
               "properties": { 
                "created_at": { 
                 "properties": { 
                  "lt": { 
                   "type": "string" 
                  } 
                 } 
                } 
               } 
              } 
             } 
            }, 
            "query": { 
             "properties": { 
              "match_all": { 
               "type": "object" 
              } 
             } 
            } 
           } 
          }, 
          "range": { 
           "properties": { 
            "created_at": { 
             "properties": { 
              "lt": { 
               "type": "string" 
              }, 
              "lte": { 
               "type": "string" 
              } 
             } 
            } 
           } 
          } 
         } 
        }, 
        "reference": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "source": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "start": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        }, 
        "type": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "updated_at": { 
         "type": "date", 
         "format": "yyyy-MM-dd' 'HH:mm:ss" 
        } 
       } 
      } 
     } 
} 

PUT mediadata/events/1 
{ 
    "created_at" : "2016-11-02 00:00:00" 
} 


PUT mediadata/events/3 
{ 
    "created_at" : "2016-11-03 00:00:00" 
} 

#The one to delete 
PUT mediadata/events/4 
{ 
    "created_at" : "2016-10-03 00:00:00" 
} 

#to verify that the documents are in the index 
GET mediadata/events/_search 
{ 
    "query": { 
    "range": { 
     "created_at": { 
     "lt": "2016-11-02 00:00:00" 
     } 
    } 
    } 
} 

DELETE /mediadata/events/_query 
{ 
    "query": { 
    "range": { 
     "created_at": { 
     "gt": "2016-11-02 00:00:00" 
     } 
    } 
    } 
} 
+0

감사합니다. 플러그인을 설치하고 ES를 다시 시작했습니다. 쿼리가 잘 작동하는 것 같습니다. 아직 완료되지는 않았지만 문서가 줄어들고 있습니다. 다시 한번 감사드립니다. – azekirel555

+0

@ azekirel555 여러분을 환영합니다. – Yeikel

관련 문제