Equivalent of copyField of Solr on ElasticSearch? Equivalent of copyField of Solr on ElasticSearch? elasticsearch elasticsearch

Equivalent of copyField of Solr on ElasticSearch?


There is special _all field that by default gets a copy of all other fields. You can control inclusion into the _all field using include_in_all attribute. However, you are limited to one field like this. If you need more then one, you would need to handle it on the search side by searching multiple fields.

It's also possible to achieve functionality similar to copyField by using multi_field with the "path": "just_name" attribute:

curl -XPUT localhost:9200/test-idx -d '{    "settings": {        "index": {            "number_of_shards": 1,            "number_of_replicas": 0        }    },    "mappings": {        "doc": {            "properties": {                "first_name": {                    "type": "multi_field",                    "path": "just_name",                    "fields": {                        "first_name": {"type": "string", "index": "analyzed"},                        "name": {"type": "string","index": "analyzed"}                    }                },                "last_name": {                    "type": "multi_field",                    "path": "just_name",                    "fields": {                        "last_name": {"type": "string", "index": "analyzed"},                        "name": {"type": "string","index": "analyzed"}                    }                }            }        }    }}'echocurl -XPUT localhost:9200/test-idx/doc/1 -d '{    "first_name": "Sebastien",    "last_name": "Lorber"}'echocurl -XPOST localhost:9200/test-idx/_refreshechocurl "localhost:9200/test-idx/doc/_search?q=name:Sebastien"echocurl "localhost:9200/test-idx/doc/_search?q=name:Lorber"