首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch client.indices.putMapping总是失败

ElasticSearch client.indices.putMapping总是失败
EN

Stack Overflow用户
提问于 2016-08-01 20:58:09
回答 2查看 4K关注 0票数 1

我真的不明白医生的意思。即使在阅读了一些这样的问题和答案之后(例如:this one)。我有这个密码

代码语言:javascript
复制
let indexMapping = {
  'foo': {
    name: { type: 'string', index: 'analyzed' },
    value: { index: 'no' },
    dynamic_templates: [ {
      customRule: {
        path_match: 'bar.*',
        mapping: { type: '{dynamic_type}', index: 'no' }
      }
    } ]
  }
};
let indexName = 'foos';
let typeName = 'foo';

client.indices.putMapping({
  index: indexName,
  type: typeName,
  [typeName]: {
    properties: indexMapping[typeName]
  }
}).catch(function (err) {
  console.error(err.stack || err);
});

我总是能得到

错误: action_request_validation_exception验证失败: 1:映射源为空;

我做错了什么?

更多信息

我的索引是新创建的,并且没有添加任何文档或当前定义的任何类型。这是一个新的、空白的索引,我想在添加和索引文档之前设置映射。

EN

回答 2

Stack Overflow用户

发布于 2016-08-02 05:12:33

动态模板声明应该与映射类型的properties级别相同,因此您的代码应该如下所示:

代码语言:javascript
复制
let indexName = 'foos';
let typeName = 'foo';

let indexMapping = {
  'properties': {
    [typeName]: {
      name: { type: 'string', index: 'analyzed' },
      value: { type: 'string', index: 'no' }
    }
  },
  'dynamic_templates': [ {
      customRule: {
          path_match: 'bar.*',
          mapping: { type: '{dynamic_type}', index: 'no' }
      }
  } ]
};

client.indices.putMapping({
  index: indexName,
  type: typeName,
  body: indexMapping
}).catch(function (err) {
  console.error(err.stack || err);
});
票数 1
EN

Stack Overflow用户

发布于 2016-08-01 21:07:53

您使用的语法有点不正确,您的最后调用应该如下所示:

代码语言:javascript
复制
client.indices.putMapping({
  index: 'foos',
  type: 'foo',
  body: {
    "foo": {
      properties: {
        name: {
          type: 'string',
          index: 'analyzed'
        },
        value: {
          index: 'no'
        },
        dynamic_templates: [{
          customRule: {
            path_match: 'bar.*',
            mapping: {
              type: '{dynamic_type}',
              index: 'no'
            }
          }
        }]
      }
    }
  }
}).catch(function(err) {
  console.error(err.stack || err);
});

还要注意,您必须像为value那样为name定义一个类型,而动态模板部分也缺少fields对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38708006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档