PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 25, 2022

[FIXED] How to restrict fields not to get stored in the elastic search database using mapping

 October 25, 2022     elasticsearch, java     No comments   

Issue

I have a mapping for an index (some_index) as mentioned below.

 {
      "_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. But record JSON will contains these fields. 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. I am working on a project where java code is written very generic and we can not do any changes over there. Any input will much appreciated.

Thanks


Solution

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:

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"
}


Answered By - Val
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing