elasticsearch:使用 javascript 创建带有映射的索引 [英] elasticsearch: create index with mappings using javascript

查看:28
本文介绍了elasticsearch:使用 javascript 创建带有映射的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的代码如下:

client.indices.create({索引: "aName",映射":{一种": {特性": {"aProp1": { "type": "string", "index": "not_analyzed" },"aProp2": { "type": "string", "index": "not_analyzed" },"aProp3": { "type": "string", "index": "not_analyzed" },"aProp4": { "type": "string", "index": "not_analyzed" }}}}},函数(错误,响应,响应代码){控制台日志(错误,响应,响应代码);});

然而……索引已创建,但没有映射……输出为:

<前>未定义 { ok: true, 确认: true } 200

我做错了什么?

解决方案

完善 Sander Spilleman 上面评论中的答案.mappings"属性需要在body"属性内.我也在使用 Javascript 客户端 1.3.0,但文档仍未更新示例.

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

var body = {鸣叫:{特性:{标签:{类型":字符串",索引":not_analyzed"},类型:{类型":字符串",索引":not_analyzed"},命名空间:{类型":字符串",索引":not_analyzed"},tid:{类型":字符串",索引":not_analyzed"}}}}client.indices.putMapping({index:"tweets", type:"tweet", body:body});

I'm trying to create an elasticsearch index with mappings using the official javascript client.

My code is as follows:

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);
});

However... the index is created but without the mappings.... The output is:

undefined { ok: true, acknowledged: true } 200

What am I doing wrong?

解决方案

Refining the answer that is in the comment above from Sander Spilleman. The "mappings" property needs to be inside the "body" property. I am also using the Javascript client 1.3.0 and the docs are still not updated with an example.

Adding an example that worked for me with the javascript API provided by elasticsearch on NPM 1.3.0

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 创建带有映射的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆