嵌入式Elasticsearch上的查询删除请求返回错误

时间:2019-10-01 06:40:07

标签: elasticsearch elasticsearch-5

我有一个单元测试,可以启动嵌入式Elasticsearch(5.2.1版)。基本的API与apache HttpClient请求一起使用。但是_delete_by_query会引发以下错误

请求

 POST http://localhost:54921/INDEX/_delete_by_query
{
  "query": {
    "term": {
      "journalId": {
        "value": "11111"
      }
    }
  }
}

响应

{
    "error": {
        "root_cause": [
            {
                "type": "invalid_type_name_exception",
                "reason": "Document mapping type name can't start with '_', found: [_delete_by_query]"
            }
        ],
        "type": "invalid_type_name_exception",
        "reason": "Document mapping type name can't start with '_', found: [_delete_by_query]"
    },
    "status": 400
}

我尝试将文档类型添加到URL(POST http://localhost:54921/INDEX/TYPE/_delete_by_query),但随后返回201。

似乎嵌入式服务器没有实现_delete_by_query。我还尝试将依赖项添加到reindex-client,但似乎没有任何效果。

请注意,如果我在独立服务器上执行相同的请求,它将正常工作。

2 个答案:

答案 0 :(得分:0)

我能够通过添加_delete_by_query来启用ReindexPLugin API

val elasticSearchSettings = Settings.builder()
            .put("http.enabled", "true")
            .put("transport.type", "netty4")
            .put("http.type", "netty4")
            .put("http.port", port)
            .put("path.data", dataDirectory)
            .put("path.home", dataDirectory)
        node = MyNode(elasticSearchSettings.build(), listOf(Netty4Plugin::class.java, ReindexPlugin::class.java)).apply { start() }

答案 1 :(得分:0)

我认为您应该在typeindex之间输入_delete_by_query的名称,例如:

POST http://localhost:54921/INDEX/TYPE_NAME/_delete_by_query

TYPE_NAME是要从中删除的索引类型。