elasticsearch:使用 javascript 创建带有映射的索引

标签 elasticsearch javascript

我正在尝试使用官方 javascript 客户端创建带有映射的 elasticsearch 索引。

我的代码如下:

client.indices.create({
    index: "aName",
    "mappings": {
        "aType": {
            "properties": {
                "aProp1": { "type": "string", "index": "not_analyzed" },
                "aProp2": { "type": "string", "index": "not_analyzed" },
                "aProp3": { "type": "string", "index": "not_analyzed" },
                "aProp4": { "type": "string", "index": "not_analyzed" }
            }
        }
    }
}, function(err,resp,respcode){
    console.log(err,resp,respcode);
});

但是...创建了索引但没有映射.... 输出是:

undefined { ok: true, acknowledged: true } 200

我做错了什么?

最佳答案

细化上述来自 Sander Spilleman 的评论中的答案。 “映射”属性需要位于“正文”属性内。我也在使用 Javascript 客户端 1.3.0,但文档仍未更新示例。

在 NPM 1.3.0 上使用 elasticsearch 提供的 javascript API 添加一个对我有用的示例

var body = {
    tweet:{
        properties:{
            tag         : {"type" : "string", "index" : "not_analyzed"},
            type        : {"type" : "string", "index" : "not_analyzed"},
            namespace   : {"type" : "string", "index" : "not_analyzed"},
            tid         : {"type" : "string", "index" : "not_analyzed"}
        }
    }
}

client.indices.putMapping({index:"tweets", type:"tweet", body:body});

关于elasticsearch:使用 javascript 创建带有映射的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22325708/

相关文章:

amazon-web-services - 允许VPC中的Lambda访问同一VPC中的Elasticsearch域

java - 如何使用Java High Level Rest Client API映射elasticsearch查询的结果集?

java - 尝试使用 ElasticSearch 存储和获取一些数据

javascript - Vueify 上的 Vuejs 递归组件

javascript - 我们如何为不同的请求类型编写 Joi 模式?

javascript - 正则表达式从 youtube url 中提取视频 ID 或播放列表 ID

elasticsearch - Elasticsearch Geospatial给了我夸张的距离测量

elasticsearch - ES_dsl.Q()中 “path”的功能是什么?

javascript - 我如何测量javascript中点击和释放之间的时间?

javascript - 为什么Unity 2018.2 WebAssembly加载间隔只有0%、90%、100%