Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java API example for storing search templates in .scripts #7321

Closed
ppf2 opened this issue Aug 18, 2014 · 0 comments

Comments

@ppf2
Copy link
Member

commented Aug 18, 2014

Would be nice to provide a Java API example for storing search templates in the .scripts index.

Here is an example:

import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptResponse;
import org.elasticsearch.script.ScriptService;

import java.util.HashMap;
import java.util.Map;

            PutIndexedScriptResponse scriptResponse = client.preparePutIndexedScript("mustache", "mysearchtemplate",
                    "{" +
                    "\"template\":{" +
                        "\"query\":{" +
                            "\"match\":{" +
                                "\"comments\" : \"{{query_string}}\"}" +
                            "}" +
                        "}" +
                    "}").get();
            Map<String, String> template_params = new HashMap<String, String>();
            template_params.put("query_string", "some_text");
            SearchResponse searchResponse = client.prepareSearch("my_index").setTypes("my_type").
                    setTemplateName("mysearchtemplate").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(template_params).get();

@dadoonet dadoonet self-assigned this Aug 18, 2014

dadoonet added a commit to dadoonet/elasticsearch that referenced this issue Dec 3, 2014
dadoonet added a commit that referenced this issue Dec 3, 2014
[Doc] Java API: add search templates
Closes #7321.

(cherry picked from commit ee108e5)
dadoonet added a commit that referenced this issue Dec 3, 2014
[Doc] Java API: add search templates
Closes #7321.

(cherry picked from commit ee108e5)

@dadoonet dadoonet closed this in 778f76a Dec 3, 2014

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
[Doc] Java API: add search templates
Closes elastic#7321.

(cherry picked from commit ee108e5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.