0
votes

Does elastic search provide a functionality to map different fields to a single field and use that single field for search.

For eg _all refers to all the fields in the docs.

Similarly do we have any mapping configuration to define a field which would be referring to multiple fields.

Eg : I have a field called Brand,Name,Category.

I need to map Brand and Name to a single field custome_field.

I want it during mapping time and not during query time. I know cross fields does that during query time.

1

1 Answers

6
votes

Take a look at copy_to functionality. It acts just like a custom _all. See here more about this:

In Metadata: _all field we explained that the special _all field indexes the values from all other fields as one big string. Having all fields indexed into one field is not terribly flexible though. It would be nice to have one custom _all field for the person’s name, and another custom _all field for their address.

Elasticsearch provides us with this functionality via the copy_to parameter in a field mapping:

PUT /my_index {
    "mappings": {
        "person": {
            "properties": {
                "first_name": {
                    "type":     "string",
                    "copy_to":  "full_name" 
                },
                "last_name": {
                    "type":     "string",
                    "copy_to":  "full_name" 
                },
                "full_name": {
                    "type":     "string"
                }
            }
        }
    } }