使用 nodejs lib 在 elasticsearch 上执行原始查询

Execute raw query on elasticsearch with nodejs lib

我可以使用 NodeJS Elastcsearch 库 (https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/quick-start.html) 执行搜索。

有没有办法对索引执行原始查询?我可以执行这样的操作吗:

PUT index
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}

... 并得到 JSON 的结果,就像使用 Kibana 一样。这可能吗?

您可以使用 indices.create

client.indices.create([params, [callback]])

例子

client.indices.create({
   index: "persons",
   body: {
       "settings" : {
       "number_of_shards" : 1
       },
       "mappings" : {
          "type1" : {
            "properties" : {
            "field1" : { "type" : "text" }
           }
        }
     }
   }
})

查看文档 indices.create