使用node.js lib在Elasticsearch上执行原始查询

时间:2018-10-18 14:50:01

标签: node.js elasticsearch kibana

我可以使用NodeJS Elastcsearch lib(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"
        }
      }
    }
  }
}

...就像使用Kibana一样以JSON格式获取结果。这可能吗?

1 个答案:

答案 0 :(得分:1)

您可以使用 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