Last active
November 12, 2016 22:43
-
-
Save umeshdangat/882caf25fdfd6090855a1252f210067c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample.elasticsearch.plugins.sample; | |
import org.elasticsearch.common.Nullable; | |
import org.elasticsearch.index.fielddata.ScriptDocValues; | |
import org.elasticsearch.plugins.Plugin; | |
import org.elasticsearch.plugins.ScriptPlugin; | |
import org.elasticsearch.script.AbstractDoubleSearchScript; | |
import org.elasticsearch.script.ExecutableScript; | |
import org.elasticsearch.script.NativeScriptFactory; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Map; | |
public class MyNativeScriptPlugin extends Plugin implements ScriptPlugin { | |
@Override | |
public List<NativeScriptFactory> getNativeScripts() { | |
return Collections.singletonList(new MyNativeScriptFactory()); | |
} | |
public static class MyNativeScriptFactory implements NativeScriptFactory { | |
@Override | |
public ExecutableScript newScript(@Nullable Map<String, Object> params) { | |
return new MyNativeScript(); | |
} | |
@Override | |
public boolean needsScores() { | |
return false; | |
} | |
@Override | |
public String getName() { | |
return "my_script"; | |
} | |
} | |
public static class MyNativeScript extends AbstractDoubleSearchScript { | |
@Override | |
public double runAsDouble() { | |
final ScriptDocValues.BytesRefs attrFlags = (ScriptDocValues.BytesRefs) doc().get("qa_data"); | |
//Example: Code which deserializes the byte array back for the plugin. | |
//CustomData[] arr = CustomDataParser.deserialize(attrFlags.get(0).bytes); | |
return arr[0].getUniqueId(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment