我尝试从elasticsearch javascript客户端调用putMapping,但始终收到状态码为400,llegal_argument_exception的错误。

当我为“文档”索引调用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
    }
  }
}

最佳答案

index:'not_analyzed'-我这样做是为了使用“term”方法来精确查找字符串,但是在Elasticsearch 2.x版本中不推荐使用(index:'not_analyzed')。现在,我只使用field.keyword:'查询字符串'来查找确切的字符串。

关于node.js - 没有消息的putMapping invalid_argument_exception,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57563905/

10-11 08:30