gpt4 book ai didi

node.js - NodeJS- Elasticsearch 以插入要索引的数据

转载 作者:行者123 更新时间:2023-12-03 01:20:52 24 4
gpt4 key购买 nike

我遵循this link来获取 flex 搜索索引的映射,并希望按如下所示将数据(不包括所有字段)插入其中,但是失败了。

索引映射:

{
"mymapping": {
"mappings": {
"_meta": {
"beat": "apm",
"version": "7.5.0"
},
"dynamic_templates": [
{
"labels": {
"path_match": "labels.*",
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
],
"properties": {
"@timestamp": {
"type": "date"
},
"people": {
"dynamic": "false",
"properties": {
"id": {
"type": "keyword",
"ignore_above": 1024
},
"name": {
"type": "keyword",
"ignore_above": 1024
}
}
}
}
}
}
}

我准备的client.js没问题,这是InsertData.js:
const esClient = require('./client');
const insertDoc = async function(indexName, _id, mappingType, data){
return await esClient.index({
index: indexName,
type: mappingType,
id: _id,
body: data
});
}

module.exports = insertDoc;
async function test(){
const data = {
beat: 'apm',
version: '7.5.0'
}
try {
const resp = await insertDoc('mymapping', 2, '_meta', data);
console.log(resp);
} catch (e) {
console.log(e);
}
}
test();

当我尝试插入数据时,出现异常。
错误输出:
message:  
'[illegal_argument_exception] Rejecting mapping update to [mymapping] as the final mapping would have more than 1 type: [_doc, _meta]',
path: '/mymapping/_doc/2',
query: { type: '_meta' },
body:
{ error:
{ root_cause: [Array],
type: 'illegal_argument_exception',
reason:
'Rejecting mapping update to [mymapping] as the final mapping would have more than 1 type: [_doc, _meta]' },
status: 400 },
statusCode: 400,
response:
'{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [mymapping] as the final mapping would have more than 1 type: [_doc, _meta]"
}
],
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [mymapping] as the final mapping would have more than 1 type: [_doc, _meta]"
},
"status": 400
}'

如何正确插入数据?

最佳答案

不建议使用Elasticsearch 6+多种类型。您正在尝试在创建映射时显式地放置类型,该映射是meta,默认插入的类型是_doc

有关更多详细信息,请参见:Removal of types

关于node.js - NodeJS- Elasticsearch 以插入要索引的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60182695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com