简体   繁体   English

如何使用映射限制字段不存储在弹性搜索数据库中

[英]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.

相关问题 如何使用弹性搜索RestHighLevelClient在java中编写json映射? - How to write json mapping in java using elastic search RestHighLevelClient? Spring数据弹性搜索中的@query注释以限制字段 - @query annotation in Spring data elastic search to restrict fields 在 java 中获取弹性搜索响应中的字段 - get fields in Elastic search response in java 如何通过 Java 高级 rest 客户端在 Elastic Search 中使用多个字段进行搜索 - How to search using multiple fields in Elastic Search through Java high level rest client 如何在spring boot中使用弹性搜索模板id(存储在ES集群中)得到结果 - How to use elastic search template id(stored in ES cluster) in spring boot get result 我可以使用Elastic Search Java API按多个字段进行搜索吗? - Can I search by multiple fields using the Elastic Search Java API? 使用 Java 字段映射弹性索引字段的问题 - Issues with Mapping Elastic Index fields with Java Fields 在弹性搜索中由一个字段聚合,然后由两个字段使用日期范围聚合 - In elastic search aggregate by one field then by two fields using date range 无法使用 TERMS QUERY 从 ELASTIC SEARCH 查询字母数字字段 - Not able to Query alphanumeric fields from ELASTIC SEARCH using TERMS QUERY 我如何按所有字段(Spring)进行弹性搜索? - How i can do Elastic search by all fields (Spring)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM