Elasticsearch how exclude fields from dynamic mapping

Viewed 637

Working with Elasticsearch version 7

My purpose is define dynamic mapping with 3 sections :

  1. Dynamic area (all string and array of will add dynamically)
  2. Add static mapping of all other known fields.
  3. Deny all known fields on top of the dynamic mapping

I success handle dynamic mapping + static area ( 1,2 section) the deny sections unfortunately cannot create.

Attached Doc -

  {
      "_index": "index_test",
      "_type": "_doc",
      "_id": "8ed19f94-11e2-417c-998d-a21275d7fb18",
      "_score": 1.0,
      "_source": {
  / *********************************** known static mapping as free text *********** /
        "source": "S3 Large Bucket of Files",
        "scanner_type_group": "unstructured",
        "my_type": "file",
 / ************************************** dynamic fileds *********** /
        "dynamic_field_1": "S3 Large Bucket of Files",
        "dynamic_field_2": " foo 123",
        "fullyQualifiedName": "S3 Large Bucket of Files.hyper-scan-test",
        "columnOrFieldOccurrencesCounter": [
          {
            "fieldName": "fileContent"
          }
        ],
   /************************************* Ignore these fileds *********** / 
        "longNumber": 1622721252657,
        "floatNumber": 1.6227213E12,
        "discard1": " This static field should be ignored!!!",
        "discard2": " This static field should be ignored too!!!",
        "discard_array": [" aaa" ,"sss"]
      }
    }

So far, I created Mapping/settings but without deny section :(

{
  "dynamic_templates": [
    {
      "strings_as_keywords": {
        "match_mapping_type": "string",
        "mapping": {
          "type": "text",
          "analyzer": "autocomplete"
        }
      }
    }
  ],
  "properties": {
    "source": { "type": "keyword" },
    "scanner_type_group": { "type": "keyword" },
    "my_type": { "type": "keyword" }
  },
   // How ignore the following property not indexed to ES  ???
   // 1. ignore all numeric types from dynamic mappings
   // 2. ignore other static mappings name: and array name discard_array
   // 3. choose  ignore either to store with/without index
   
}

the settings for text (It works)

{
  "analysis": {
    "filter": {
      "autocomplete_filter": {
        "type": "ngram",
        "min_gram": 2,
        "max_gram": 20
      }
    },
    "analyzer": {
      "autocomplete": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "lowercase",
          "autocomplete_filter"
        ]
      }
    }
  },
  "max_ngram_diff": 30,
  "index": {
    "number_of_shards": 5,
    "number_of_replicas": 0
  }
}

any suggestions how ignore numeric types and specific fields + array (as mentioned in the json) .

Thanks

0 Answers
Related