【问题标题】:putMapping illegal_argument_exception without messageputMapping 非法参数异常没有消息
【发布时间】:2019-08-21 20:15:36
【问题描述】:

我尝试从 elasticsearch javascript 客户端调用 putMapping,但总是收到错误,状态码为 400,非法参数异常。

当我为“文档”索引调用 getMapping 时,我得到了:

 {
"documents":{
    "mappings": {
         "properties":{
              "category":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "createdAt":{"type":"text","fields":{"keyword":                                          
                         {"type":"keyword","ignore_above":256}}},
              "id":{"type":"text","fields":{"keyword":                                                                  
                         {"type":"keyword","ignore_above":256}}},
              "info":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "text":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "title":{"type":"text","fields":{"keyword": 
                         {"type":"keyword","ignore_above":256}}},
              "visibility":{"type":"boolean"}
            }
    }
}
}

我尝试使用相同的属性调用 putMapping,并在类别字段中添加一个新参数 'index': 'not_analyzed':

esClient.indices.putMapping({
            index: 'documents',
            type: 'document',
            body: {
                document: {
                    properties: {
                        title: { type: 'text' },
                        info: { type: 'text' },
                        text: { type: 'text' },
                        category: { type: 'text', index: 
                           'not_analyzed' 
                        },
                        visibility: { type: 'boolean' },
                        createdAt: { type: 'text' },
                    },
                },
            },
        }, (err, resp) => {
            if (err) {
                console.error(err);
            }
            else {
                console.log('Successfully Created Index', resp);
            }
        });

我收到了这个错误:

ResponseError: illegal_argument_exception
    at IncomingMessage.<anonymous> (/Users/user/reference_sys_cfu-back/node_modules/@elastic/elasticsearch/lib/Transport.js:287:25)
    at IncomingMessage.emit (events.js:208:15)
    at IncomingMessage.EventEmitter.emit (domain.js:476:20)
    at endReadableNT (_stream_readable.js:1168:12)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  name: 'ResponseError',
  meta: {
    body: { error: [Object], status: 400 },
    statusCode: 400,
    headers: {
      'content-type': 'application/json; charset=UTF-8',
      'content-length': '345'
    },
    warnings: null,
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 0,
      aborted: false
    }
  }
}

【问题讨论】:

    标签: node.js elasticsearch


    【解决方案1】:

    index: 'not_analyzed' - 我这样做是为了使用“term”方法来精确查找字符串,但它(索引:'not_analyzed')在 2.x 版本的 elasticsearch 中已弃用。现在我只使用 field.keyword: 'query string' 来查找确切的字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 2014-04-05
      相关资源
      最近更新 更多