Can someone tell me if there's an equivalent of Solr copyField directive on ElasticSearch?
I know there is the multi-field type: http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html It is nice when you want to apply multiple analyzers on the same field.
But it's not exactly the same. Solr permits to "merge" multiple fields into one:
<field name="id" type="string" indexed="true" stored="true"/>
<field name="name" type="string" indexed="true" stored="true"/>
<field name="subject" type="string" indexed="true" stored="true"/>
<field name="location" type="string" indexed="true" stored="true"/>
<field name="all" type="text" indexed="true" stored="true" multiValued="true"/>
<copyField source="*" dest="all"/>
This plugin is pretty promising: https://github.com/yakaz/elasticsearch-analysis-combo
Because it permits to get back the results as a single field when using an ElasticSearch multi value field. But it's still not exactly the same because it doesn't permit to "merge" multiple fields.
I would like a combination of both Combo analyzer and Solr copyField.
I have a blog post model (title/description fields) and would like to copy both the title and description on a single field "blogContent" on which I'll apply 2 different analyzers.
Is there a solution in 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"}
}
}
}
}
}
}'
echo
curl -XPUT localhost:9200/test-idx/doc/1 -d '{
"first_name": "Sebastien",
"last_name": "Lorber"
}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Sebastien"
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Lorber"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With