【问题标题】:include_type_name parameter is set to true in node.js在 node.js 中 include_type_name 参数设置为 true
【发布时间】:2019-12-11 00:00:03
【问题描述】:

我正在尝试在 MongoDB 和 elasticsearch 之间创建映射。我正在使用 mongoosastic。当我尝试创建新映射时,出现以下错误。

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

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;

回应: '{"error":{"root_cause":[{"type":"illegal_argument_exception","re​​ason":"类型 不能在放置映射请求中提供,除非 include_type_name 参数设置为 true."}],"type":"illegal_argument_exception","re​​ason":"类型不能 在放置映射请求中提供,除非 include_type_name 参数设置为 true。"},"status":400}',

我不知道如何在 node.js/mongoosastic 中添加 include_type_name 参数设置为 true

这是我的代码

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/mongoosastic/mongoosastic/blob/master/example/blog/app.js 的使用代码。我是 node.js、MongoDB、elasticsearch 的新手。

我有一个 MongoDB 数据库,我正在尝试使用 elasticsearch 进行映射。如果它在 MongoDB 中添加数据,我想加入两者,然后它将自动添加到 elasticsearch DB。我只想使用 elasticsearch 搜索数据,否则我将使用 MongoDB。

【问题讨论】:

    标签: node.js mongodb elasticsearch mapping mongoosastic


    【解决方案1】:

    我认为您不能直接将参数添加到 typeName。如果您检查来自 elasticsearch javascript 客户端的代码,您会发现它对您的类型名进行了编码以逃避那些 URI 字符:Link here。参数中的 ? 将被编码,使其成为类型的一部分。

    这个我还没有验证过,但是从elasticsearch-js读取代码放映射函数,我想你可能想试试这个:

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

    【讨论】:

      猜你喜欢
      • 2019-09-06
      • 2019-09-15
      • 2020-10-29
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多