在node.js中将include_type_name参数设置为true [英] include_type_name parameter is set to true in node.js

查看:413
本文介绍了在node.js中将include_type_name参数设置为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MongoDB和elasticsearch之间创建映射.我正在用monososastic.当我尝试创建新的映射时,会出现以下错误.

I'm trying to create a mapping between MongoDB and elasticsearch. I'm using mongoosastic for it. When I'm trying to create new mapping it gives me following error.

对于解决方案,我在 https:/上添加?Finclude_type_name=true /github.com/mongoosastic/mongoosastic/blob/master/lib/mongoosastic.js

For solution, i have add ?Finclude_type_name=true on https://github.com/mongoosastic/mongoosastic/blob/master/lib/mongoosastic.js

function createMappingIfNotPresent (options, cb) {
    const client = options.client;
    const indexName = options.indexName;
    const typeName = options.typeName+"?Finclude_type_name=true";
    const schema = options.schema;
    const settings = options.settings;
    const properties = options.properties;

响应: '{错误":{"root_cause":[{类型":"illegal_argument_exception",原因":类型 不能在放置映射请求中提供,除非 include_type_name参数设置为 true.}]," type:" illegal_argument_exception," reason:"类型不能为 放置映射请求中提供的,除非include_type_name 参数设置为true.},"状态:400}',

response: '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."}],"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."},"status":400}',

我不知道如何在node.js/mongoosastic

I have no ideahow to add include_type_name parameter is set to true in node.js/mongoosastic

这是我的代码

var model_catagories = "products";

productsSchema.plugin(mongoosastic);

// Export Contact model
var Products =  module.exports = mongoose.model(model_catagories, productsSchema);

Products.createMapping({  include_type_name: true }, function(err, mapping) {
  if (err) {
    console.log('error creating mapping (you can safely ignore this)');
    console.log(err);
  } else {
    console.log('mapping created!');
    console.log(mapping);
  }
});

我有 https://github.com com/mongoosastic/mongoosastic/blob/master/example/blog/app.js 听到.我是node.js,MongoDB,elasticsearch中的新手.

I have use code for https://github.com/mongoosastic/mongoosastic/blob/master/example/blog/app.js hear. I'm new in node.js, MongoDB, elasticsearch.

我有一个MongoDB数据库,我正在尝试使用elasticsearch进行映射.如果要在MongoDB中添加数据,我想将两者都加入,那么它将在Elasticsearch DB上自动添加.我只想使用elasticsearch搜索数据,否则我将使用MongoDB.

I have a database of MongoDB I'm trying to Mapping with elasticsearch. I want to join both if it adds data in MongoDB on then it will automatically add on elasticsearch DB. I want to only search data using elasticsearch otherwise i will use MongoDB.

推荐答案

我认为您不能直接向typeName添加参数.如果您从elasticsearch javascript客户端检查代码,您会发现它编码了您的类型名以逃避那些URI字符:

I don't think you could add parameter directly to the typeName. If you check the code from elasticsearch javascript client, you would find that it encode your typename to escape from those URI chars: Link here. Your ? in the parameter would be encoded such that it would be part of the type.

我尚未验证这一点,但是从elasticsearch-js读取代码后,我将映射功能放到了我想您可以尝试以下方法:

I have not verified this, but reading code from elasticsearch-js put mapping function, I think you might want to try this:

  ...
  return client.indices.putMapping({
    index: indexName,
    type: typeName,
    body: completeMapping,
    includeTypeName: true // Add parameter for your put mapping.
  }, (err) => {
    cb(err, completeMapping[typeName])
  })
  ...

这篇关于在node.js中将include_type_name参数设置为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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