通过嵌入式 elasticsearch returns 错误的查询请求删除

delete by query request on embedded elasticsearch returns error

我有一个启动嵌入式弹性搜索(版本 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),但后来 returns 201。

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

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

我能够通过添加 ReindexPLugin

来启用 _delete_by_query 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() }

我认为你应该把 type 名字放在 index_delete_by_query 之间,比如:

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

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