Overview
ES supports groovy and Java two language custom score calculations, groovy can even be nested in the requested parameters, a little bit, but not in the scope of this discussion.
How to use custom Java code to define how score is generated, which uses the ES plugin function
For more information about the ES plugin, you can use the following command to obtain
./bin elasticsearch-plugn–h
Action Step 1. Add configuration
First you need to add the following in the ES configuration,
The old version is
False
The currently used ES is 5.2.2, according to the log prompt, changed to the following, after the change to restart ES
Script.inline:truescript.stored:true
I have to say, this log provides a good message.
If you do not add these two configurations, this error
2. Write Java code
Java Code Format Reference
Https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting-native.html
3. Write the configuration file
Configuration file Format Reference
Https://github.com/elastic/elasticsearch/blob/master/buildSrc/src/main/resources/plugin-descriptor.properties
4. Uploading to the ES cluster
Create a new folder in $elasticsearch_home/plugins, the name of this folder is the name of the plugin,
For example, there are three of folders
You can find them by following the command
In the new folder, import the jar Package and the plugin-descriptor.properties file (must have)
5. Restart the ES service
Kill-9 PID
Nohup./elasticsearch &
5. Use
{ "query": {"Function_score" : {"Query " : {"Match": { "Your_fields": "xxxx" } , "Functions": [ { "Script_score": { "Script":{ "inline": "Key", "lang": "Native", "params" : { "your_fields": "xxxxx" } }}}}}}
Key explanation:
Key |
Explain |
Note |
Inline |
Call the plugin's key, and the plugin name is two things |
In the Nativescriptfactory interface, the GetName () method settings |
Lang |
Custom mode |
Native meaning is implemented with Java native |
About customizing Function-script-score
Https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-function-score-query.html#function-script-score
6. Updating plugins
Because ES cluster will cache plug-in code, even if the plugin is still available to delete, still need to restart to update the plugin
Resources
Steps necessary to customize the Java authoring plugin
Https://www.elastic.co/guide/en/elasticsearch/plugins/5.2/plugin-authors.html#_plugin_structure
GitHub Full Plugin
Https://github.com/momoxixi/elasticsearch-feature-vector-scoring
Elasticsearch Series (vii) Java definition Score