Skip to content

Simple solution to the issue with Data management > Dynamic template task #5

Description

@er1kb

Hi!

Many thanks for making this resource available for the rest of us! It's a goldmine.

Your example for the dynamic template works, it's just that the copy_to field does not show up in the _source part of the response. The documentation states that "The original _source field will not be modified to show the copied values".

The copy_to field still exists outside of _source and is searchable. To verify this with the example taken from the documentation:

POST my_index/_search
{
  "query": {
    "wildcard": {
      "full_name": {
        "value": "*John*",
        "case_insensitive": true
      }
    }
  }
}
# Returns the one document

My solution to the task focusing on the accounts data:

DELETE /_index_template/accounts-tmpl
DELETE accounts-fullname
# Then import the data with curl
PUT /_index_template/accounts-tmpl
{
  "index_patterns": [
    "accounts-*"
  ],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    },
    "mappings": {
      "dynamic_templates": [
        {
          "fullname": {
            "path_match": "*name",
            "mapping": {
              "type": "text",
              "copy_to": "fullname"
            }
          }
        }
      ],
      "properties": {
        "account_number": {
          "type": "integer"
        },
        "balance": {
          "type": "long"
        },
        "firstname": {
          "type": "text",
          "copy_to": "fullname"
        },
        "lastname": {
          "type": "text",
          "copy_to": "fullname"
        },
        "gender": {
          "type": "keyword"
        },
        "address": {
          "type": "text"
        },
        "employer": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "email": {
          "type": "keyword"
        },
        "city": {
          "type": "keyword"
        },
        "state": {
          "type": "keyword"
        }
      }
    }
  }
}

GET accounts-fullname/_mappings
# A mapping has been created for the fullname field

GET accounts-fullname/_search
{
  "query": {
    "wildcard": {
      "fullname": {
        "value": "*Duke*",
        "case_insensitive": true
      }
    }
  }
}
# This returns 2 documents
# Again, the copy_to field is searchable, but not visible through _source

Cheers / Erik

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions