gpt4 book ai didi

Elasticsearch如何在索引中排除一些字段

转载 作者:行者123 更新时间:2023-12-02 22:15:54 29 4
gpt4 key购买 nike

我有一个JSON数据,当我为数据建立索引时,该数据会通过 Elasticsearch 自动映射。如何排除映射中的某些字段。我已经尝试过手动定义 map ,但是当我执行批量索引时,它会自动映射其他字段。

前任。我的JSON数据如下所示

[
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
},
...

我手动定义 map 时
PUT myindex
{
"mappings": {
"product": {
"properties": {
"id": { "type": "text },
"name": { "type": "text"},
"description": { "type": "text" },
"is_active": { "type": "boolean" }
}
}
}
}

我要实现的是数据仍然保留,我只想排除不包含在索引中的image属性。

这样当我在 Elasticsearch 中查询仍然是带有图像的数据时

那可能吗?

感谢你们。我是Elasticsearch的新手
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
}

最佳答案

是的,只需将 dynamic: false 添加到您的映射即可,如下所示:

PUT myindex
{
"mappings": {
"product": {
"dynamic": false, <-- add this line
"properties": {
"id": {
"type": "text"
},
"name": {
"type": "text"
},
"description": {
"type": "text"
},
"is_active": {
"type": "boolean"
}
}
}
}
}
image数组仍将在源中,但不会修改映射。

关于Elasticsearch如何在索引中排除一些字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51182783/

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