使用Javascript API deleteByQuery()时不会删除文档?

时间:2017-02-26 11:25:38

标签: javascript elasticsearch amazon-elasticsearch

在Javascript API中使用deleteByQuery()我想从名为people的索引中删除一些文档。

请注意,这是AWS Elastic Search Service中的版本5.1。

索引映射如下所示:

"people": {
  "mappings": {
    "person": {
      "properties": {
        "name": {
          "type": "string"
        },
        "parent_id": {
          "type": "long"
        },
        "query": {
          "properties": {
            "match": {
              "properties": {
                "parent_id": {
                  "type": "long"
                }
              }
            },
            "term": {
              "properties": {
                "parent_id": {
                  "type": "long"
                }
              }
            }
          }
        }
      }
    }
  }
}

搜索查询的结构如下:

query: {
  term: {
    parent_id: 1
  }
}

回复:

"hits": {
  "total": 1,
  "max_score": 10.135444,
  "hits": [
    {
      "_index": "people",
      "_type": "person",
      "_id": "AVp6EDRVm933W5mwl4O9",
      "_score": 10.135444,
      "_source": {
        "name": "Bob",
        "parent_id": 1
      }
    }
  ]
}

然后使用JS API的文档创建了以下内容:

const elasticsearch = require('elasticsearch')
function deletePeople (parentId) {
  new elasticsearch
  .Client({ host: 'es.host.domain' })
  .deleteByQuery({
    index: 'people',
    type: 'person',
    body: {
      query: {
        term: {
          parent_id: parentId
        }
      }
    }
  }, function afterDeletingPeople (error, response) {
    if (error) {
      return console.log("deletePeople :: Error :: ", error);
    }
    else {
      return console.log("deletePeople :: Response :: ", response);
    }
  });
};
deletePeople(1);

其中的回答如下:

info: deletePeople :: Response ::  { _index: 'people',
  _type: 'person',
  _id: '_delete_by_query',
  _version: 30,
  _shards: { total: 2, successful: 1, failed: 0 },
  created: false }

这看起来很有希望,但实际上并没有人从索引中删除。我尝试在查询中使用match而不是term,但这也是一样的。

有人可以建议我在这里出错了,因为目前我的功能删除了没有人吗? TIA!

0 个答案:

没有答案