[英]How to restrict fields not to get stored in the elastic search database using mapping
I have a mapping for an index (some_index) as mentioned below.我有一个索引(some_index)的映射,如下所述。
{
"_source": {
"enabled": false
},
"properties": {
"actions": {
"store": true,
"type": "integer"
},
"identifier": {
"store": true,
"type": "keyword"
},
"source": {
"properties": {
"entityType": {
"store": true,
"type": "keyword"
},
"topicPrefix": {
"index": false,
"type": "keyword"
}
"parentJobId": {
"store": true,
"type": "keyword"
}
}
}
}
}
Sample document样本文件
recordJson = {
"actions": 40442,
"source": {
"entityType": "DELIVERY",
"parentJobId": "a9a65756-4623-4d7b-ac5f-d2077f3509f6",
"topicPrefix": "dev"
},
"identifier": ""
}
Here I don't want to save the whole source properties into Elastic search DB.在这里,我不想将整个源属性保存到 Elastic 搜索数据库中。 But record JSON will contains these fields.
但是记录 JSON 将包含这些字段。 I only need to prevent the source properties to get store in the Elastic search db.
我只需要阻止源属性存储在弹性搜索数据库中。
Note: Is there a way we can control it using mapping only, with out doing any change in java.注意:有没有一种方法我们可以只使用映射来控制它,而不需要对 java 进行任何更改。 I am working on a project where java code is written very generic and we can not do any changes over there.
我正在开发一个项目,其中 java 代码编写得非常通用,我们无法在那里进行任何更改。 Any input will much appreciated.
任何输入将不胜感激。
Thanks谢谢
Using an ingest pipeline you can have your documents be modified just before getting indexed.使用摄取管道,您可以在被索引之前修改您的文档。 In your case, you'd like to remove the
source
field and its content, so you can easily achieve it with the following pipeline:在您的情况下,您希望删除
source
字段及其内容,因此您可以使用以下管道轻松实现它:
PUT _ingest/pipeline/remove-source
{
"processors": [
{
"remove": {
"field": "source
}
}
]
}
And then just reference that pipeline when indexing your data然后在索引数据时引用该管道
PUT my-index/_doc/1?pipeline=remove-source
{
"actions": 40442,
"source": {
"entityType": "DELIVERY",
"parentJobId": "a9a65756-4623-4d7b-ac5f-d2077f3509f6",
"topicPrefix": "dev"
},
"identifier": ""
}
If you don't want or can't specify the pipeline at indexing time, you can also configure your index to always run that pipeline when indexing documents.如果您不想或无法在索引时指定管道,您还可以将索引配置为在索引文档时始终运行该管道。 Just run the following command and nothing changes in your indexing code:
只需运行以下命令,索引代码不会发生任何变化:
PUT my-index/_settings
{
"index.default_pipeline": "remove-source"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.