我有一个 JSON 数据,当我索引数据时,它会通过弹性搜索自动映射。如何排除映射中的某些字段。我已经尝试手动定义地图,但是当我进行批量索引时,它会自动映射其他字段。
前任。我的 JSON 数据如下所示
[
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
},
...
Run Code Online (Sandbox Code Playgroud)
我手动定义时的地图
PUT myindex
{
"mappings": {
"product": {
"properties": {
"id": { "type": "text },
"name": { "type": "text"},
"description": { "type": "text" },
"is_active": { "type": "boolean" }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是数据仍然存在我只想排除不包含在索引中的图像属性。
所以当我在弹性搜索中查询时,我仍然得到带有图像的数据
那可能吗?
谢谢你们。我是弹性搜索的新手
{
"id": "232",
"name": "Lorem",
"description": "Ipsum Dolor",
"image": [
{"key": "asadasd.jpg"},
{"key": "asasd2d.jpg"}
],
"is_active": true
}
Run Code Online (Sandbox Code Playgroud)
是的,只需添加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"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该image
数组仍将在源中,但不会修改映射。
接受的答案的问题是,您需要显式添加所有字段的映射,这并不总是需要的(例如对于数组类型)。您可以像这样禁用该字段:
PUT myindex
{
"mappings": {
"product": {
"properties": {
"id": { "type": "text },
"name": { "type": "text"},
"description": { "type": "text" },
"is_active": { "type": "boolean" },
"image": { "type": "object, "enabled": false }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该image
数组仍然位于 _source 中。
参考:https ://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html
归档时间: |
|
查看次数: |
3276 次 |
最近记录: |