Skip to content

Commit

Permalink
Update to elasticsearch 1.0.0
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
dadoonet committed Mar 7, 2014
1 parent 4f617d1 commit 4d90405
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JavaScript lang Plugin for Elasticsearch
==================================

The JavaScript language plugin allows to have `javascript` as the language of scripts to execute.
The JavaScript language plugin allows to have `javascript` (or `js`) as the language of scripts to execute.

In order to install the plugin, simply run: `bin/plugin -install elasticsearch/elasticsearch-lang-javascript/2.0.0.RC1`.

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</parent>

<properties>
<elasticsearch.version>1.0.0.RC1</elasticsearch.version>
<lucene.version>4.6.0</lucene.version>
<elasticsearch.version>1.0.0</elasticsearch.version>
<lucene.version>4.6.1</lucene.version>
<tests.jvms>1</tests.jvms>
<tests.shuffle>true</tests.shuffle>
<tests.output>onerror</tests.output>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
Expand Down Expand Up @@ -112,11 +113,7 @@ public void testScriptFieldUsingSource() throws Exception {
.addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null)
.execute().actionGet();

Map<String, Object> sObj1 = (Map<String, Object>) response.getHits().getAt(0).field("_source.obj1").value();
assertThat(sObj1.get("test").toString(), equalTo("something"));
assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something"));

sObj1 = (Map<String, Object>) response.getHits().getAt(0).field("s_obj1").value();
Map<String, Object> sObj1 = (Map<String, Object>) response.getHits().getAt(0).field("s_obj1").value();
assertThat(sObj1.get("test").toString(), equalTo("something"));
assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something"));

Expand Down Expand Up @@ -145,7 +142,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running doc['num1'].value");
SearchResponse response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("doc['num1'].value").lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand All @@ -159,7 +157,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running -doc['num1'].value");
response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("-doc['num1'].value").lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand All @@ -174,7 +173,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running pow(doc['num1'].value, 2)");
response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("Math.pow(doc['num1'].value, 2)").lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand All @@ -188,7 +188,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running max(doc['num1'].value, 1)");
response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("Math.max(doc['num1'].value, 1)").lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand All @@ -202,7 +203,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running doc['num1'].value * _score");
response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("doc['num1'].value * _score").lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand All @@ -216,7 +218,8 @@ public void testCustomScriptBoost() throws Exception {
logger.info(" --> running param1 * param2 * _score");
response = client().search(searchRequest()
.searchType(SearchType.QUERY_THEN_FETCH)
.source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js")))
.source(searchSource().explain(true).query(functionScoreQuery(termQuery("test", "value"))
.add(ScoreFunctionBuilders.scriptFunction("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))))
).actionGet();

assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
Expand Down

0 comments on commit 4d90405

Please sign in to comment.