How to specify ElasticSearch copy_to for an order?

ElasticSearch has the ability to copy values ​​to other fields (index time), allowing you to search across multiple fields as if it were a single field ( Kernel Types: copy_to ).

However, there seems to be no way to indicate the order in which these values ​​should be copied. This can be important when matching phrases:

curl -XDELETE 'http://10.11.12.13:9200/helloworld' curl -XPUT 'http://10.11.12.13:9200/helloworld' # copy_to is ordered alphabetically! curl -XPUT 'http://10.11.12.13:9200/helloworld/_mapping/people' -d ' { "people": { "properties": { "last_name": { "type": "string", "copy_to": "full_name" }, "first_name": { "type": "string", "copy_to": "full_name" }, "state": { "type": "string" }, "city": { "type": "string" }, "full_name": { "type": "string" } } } } ' curl -X POST "10.11.12.13:9200/helloworld/people/dork" -d '{"first_name": "Jim", "last_name": "Bob", "state": "California", "city": "San Jose"}' curl -X POST "10.11.12.13:9200/helloworld/people/face" -d '{"first_name": "Bob", "last_name": "Jim", "state": "California", "city": "San Jose"}' curl "http://10.11.12.13:9200/helloworld/people/_search" -d ' { "query": { "match_phrase": { "full_name": { "query": "Jim Bob" } } } } ' 

Only Jim Bob returns; it seems that the fields are copied in the field name in alphabetical order.

How can I switch copy_to order to return "Jim Bob"?

+7
elasticsearch
source share
1 answer

This is more deterministically controlled by registering the transform script in your mapping.

something like that:

 "transform" : [ {"script": "ctx._source['full_name'] = [ctx._source['first_name'] + " " + ctx._source['last_name'], ctx._source['last_name'] + " " + ctx._source['first_name']]"} ] 

In addition, the conversion scripts can be "native", that is, java , codes available for all nodes in the cluster, making your custom classes available in the elasticsearch class path and registered as their own scripts using the settings:

 script.native.<name>.type=<fully.qualified.class.name> 

and in this case, in your mapping, you should register your own script as a transform as follows:

 "transform" : [ { "script" : "<name>", "params" : { "param1": "val1", "param2": "val2" }, "lang": "native" } ], 
+3
source share

All Articles