弹性搜索:使用javascript创建索引与映射 [英] elasticsearch: create index with mappings using javascript

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

问题描述



我的代码如下:

  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}
}
}
}
},函数(err,resp,respcode){
console.log(err,resp,respcode);
});

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

 
undefined {ok:true,acknowledge:true} 200

我做错了什么?

解决方案

从Sander中提炼上述评论中的答案Spilleman。 mappings属性需要在body属性内。我也使用Javascript客户端1.3.0,文档仍然没有更新一个例子。



添加一个为弹性搜索提供的JavaScript API为我工作的示例在NPM 1.3.0上

  var body = {
tweet:{
properties:{
标签:{type:string,index:not_analyzed},
type:{type:string,index:not_analyzed},
命名空间:{type:string,index:not_analyzed},
tid:{type:string,index: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});

这篇关于弹性搜索:使用javascript创建索引与映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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