parent
40f89f70f6
commit
a36827cbc0
112
pom.xml
112
pom.xml
|
@ -31,7 +31,13 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<elasticsearch.version>0.90.1</elasticsearch.version>
|
<elasticsearch.version>0.90.10</elasticsearch.version>
|
||||||
|
<lucene.version>4.6.0</lucene.version>
|
||||||
|
<tests.jvms>1</tests.jvms>
|
||||||
|
<tests.shuffle>true</tests.shuffle>
|
||||||
|
<tests.output>onerror</tests.output>
|
||||||
|
<tests.client.ratio></tests.client.ratio>
|
||||||
|
<es.logger.level>INFO</es.logger.level>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -42,6 +48,13 @@
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.lucene</groupId>
|
||||||
|
<artifactId>lucene-test-framework</artifactId>
|
||||||
|
<version>${lucene.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.elasticsearch</groupId>
|
<groupId>org.elasticsearch</groupId>
|
||||||
<artifactId>elasticsearch</artifactId>
|
<artifactId>elasticsearch</artifactId>
|
||||||
|
@ -65,9 +78,10 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testng</groupId>
|
<groupId>org.elasticsearch</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>elasticsearch</artifactId>
|
||||||
<version>6.3.1</version>
|
<version>${elasticsearch.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -98,13 +112,95 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||||
|
<artifactId>junit4-maven-plugin</artifactId>
|
||||||
|
<version>2.0.12</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>tests</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>junit4</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<heartbeat>20</heartbeat>
|
||||||
|
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||||
|
<leaveTemporary>true</leaveTemporary>
|
||||||
|
<listeners>
|
||||||
|
<report-ant-xml mavenExtensions="true"
|
||||||
|
dir="${project.build.directory}/surefire-reports"/>
|
||||||
|
<report-text
|
||||||
|
showThrowable="true"
|
||||||
|
showStackTraces="true"
|
||||||
|
showOutput="${tests.output}"
|
||||||
|
showStatusOk="false"
|
||||||
|
showStatusError="true"
|
||||||
|
showStatusFailure="true"
|
||||||
|
showStatusIgnored="true"
|
||||||
|
showSuiteSummary="true"
|
||||||
|
timestamps="false"/>
|
||||||
|
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
|
||||||
|
</listeners>
|
||||||
|
<assertions>
|
||||||
|
<enable/>
|
||||||
|
</assertions>
|
||||||
|
<parallelism>${tests.jvms}</parallelism>
|
||||||
|
<balancers>
|
||||||
|
<execution-times>
|
||||||
|
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
|
||||||
|
</execution-times>
|
||||||
|
</balancers>
|
||||||
|
<includes>
|
||||||
|
<include>**/*Tests.class</include>
|
||||||
|
<include>**/*Test.class</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/Abstract*.class</exclude>
|
||||||
|
<exclude>**/*StressTest.class</exclude>
|
||||||
|
</excludes>
|
||||||
|
<jvmArgs>
|
||||||
|
<param>-Xmx512m</param>
|
||||||
|
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||||
|
<param>-Des.logger.prefix=</param>
|
||||||
|
</jvmArgs>
|
||||||
|
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||||
|
<sysouts>${tests.verbose}</sysouts>
|
||||||
|
<seed>${tests.seed}</seed>
|
||||||
|
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||||
|
<systemProperties>
|
||||||
|
<!-- RandomizedTesting library system properties -->
|
||||||
|
<tests.iters>${tests.iters}</tests.iters>
|
||||||
|
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||||
|
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||||
|
<tests.class>${tests.class}</tests.class>
|
||||||
|
<tests.method>${tests.method}</tests.method>
|
||||||
|
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||||
|
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||||
|
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||||
|
<tests.slow>${tests.slow}</tests.slow>
|
||||||
|
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||||
|
<tests.slow>${tests.slow}</tests.slow>
|
||||||
|
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||||
|
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||||
|
<tests.integration>${tests.integration}</tests.integration>
|
||||||
|
<tests.cluster_seed>${tests.cluster_seed}</tests.cluster_seed>
|
||||||
|
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||||
|
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||||
|
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||||
|
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||||
|
<java.awt.headless>true</java.awt.headless>
|
||||||
|
</systemProperties>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<!-- we skip surefire to work with randomized testing above -->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.11</version>
|
<version>2.15</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<skipTests>true</skipTests>
|
||||||
<include>**/*Tests.java</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -23,31 +23,31 @@ import org.elasticsearch.common.collect.Lists;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.script.ExecutableScript;
|
import org.elasticsearch.script.ExecutableScript;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.junit.After;
|
||||||
import org.testng.annotations.Test;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JavaScriptScriptEngineTests {
|
public class JavaScriptScriptEngineTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
private JavaScriptScriptEngineService se;
|
private JavaScriptScriptEngineService se;
|
||||||
|
|
||||||
@BeforeClass
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS);
|
se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@After
|
||||||
public void close() {
|
public void close() {
|
||||||
se.close();
|
se.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.script.javascript;
|
package org.elasticsearch.script.javascript;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom;
|
import org.elasticsearch.common.util.concurrent.jsr166y.ThreadLocalRandom;
|
||||||
import org.elasticsearch.script.ExecutableScript;
|
import org.elasticsearch.script.ExecutableScript;
|
||||||
import org.testng.annotations.Test;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -32,16 +31,12 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
public class JavaScriptScriptMultiThreadedTest extends ElasticsearchTestCase {
|
||||||
public class JavaScriptScriptMultiThreadedTest {
|
|
||||||
|
|
||||||
protected final ESLogger logger = Loggers.getLogger(getClass());
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecutableNoRuntimeParams() throws Exception {
|
public void testExecutableNoRuntimeParams() throws Exception {
|
||||||
|
|
|
@ -21,74 +21,39 @@ package org.elasticsearch.script.javascript;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
|
||||||
import org.elasticsearch.common.network.NetworkUtils;
|
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
|
||||||
import org.elasticsearch.node.Node;
|
|
||||||
import org.elasticsearch.node.NodeBuilder;
|
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.junit.Test;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.client.Requests.*;
|
import static org.elasticsearch.client.Requests.searchRequest;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.index.query.FilterBuilders.scriptFilter;
|
import static org.elasticsearch.index.query.FilterBuilders.scriptFilter;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
public class JavaScriptScriptSearchTests extends ElasticsearchIntegrationTest {
|
||||||
public class JavaScriptScriptSearchTests {
|
|
||||||
|
|
||||||
protected final ESLogger logger = Loggers.getLogger(getClass());
|
|
||||||
|
|
||||||
private Node node;
|
|
||||||
|
|
||||||
private Client client;
|
|
||||||
|
|
||||||
@BeforeMethod
|
|
||||||
public void createNodes() throws Exception {
|
|
||||||
node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
|
|
||||||
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
|
|
||||||
.put("gateway.type", "none")
|
|
||||||
.put("number_of_shards", 1)).node();
|
|
||||||
client = node.client();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterMethod
|
|
||||||
public void closeNodes() {
|
|
||||||
client.close();
|
|
||||||
node.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJavaScriptFilter() throws Exception {
|
public void testJavaScriptFilter() throws Exception {
|
||||||
client.admin().indices().prepareCreate("test").execute().actionGet();
|
wipeIndices("test");
|
||||||
client.prepareIndex("test", "type1", "1")
|
createIndex("test");
|
||||||
.setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())
|
index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject());
|
||||||
.execute().actionGet();
|
flush();
|
||||||
client.admin().indices().prepareFlush().execute().actionGet();
|
index("test", "type1", "2", jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject());
|
||||||
client.prepareIndex("test", "type1", "2")
|
flush();
|
||||||
.setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject())
|
index("test", "type1", "3", jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject());
|
||||||
.execute().actionGet();
|
refresh();
|
||||||
client.admin().indices().prepareFlush().execute().actionGet();
|
|
||||||
client.prepareIndex("test", "type1", "3")
|
|
||||||
.setSource(jsonBuilder().startObject().field("test", "value beck").field("num1", 3.0f).endObject())
|
|
||||||
.execute().actionGet();
|
|
||||||
client.admin().indices().refresh(refreshRequest()).actionGet();
|
|
||||||
|
|
||||||
logger.info("running doc['num1'].value > 1");
|
logger.info(" --> running doc['num1'].value > 1");
|
||||||
SearchResponse response = client.prepareSearch()
|
SearchResponse response = client().prepareSearch()
|
||||||
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js")))
|
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > 1").lang("js")))
|
||||||
.addSort("num1", SortOrder.ASC)
|
.addSort("num1", SortOrder.ASC)
|
||||||
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
||||||
|
@ -100,8 +65,8 @@ public class JavaScriptScriptSearchTests {
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("3"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("3"));
|
||||||
assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0));
|
assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0));
|
||||||
|
|
||||||
logger.info("running doc['num1'].value > param1");
|
logger.info(" --> running doc['num1'].value > param1");
|
||||||
response = client.prepareSearch()
|
response = client().prepareSearch()
|
||||||
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2)))
|
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", 2)))
|
||||||
.addSort("num1", SortOrder.ASC)
|
.addSort("num1", SortOrder.ASC)
|
||||||
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
||||||
|
@ -111,8 +76,8 @@ public class JavaScriptScriptSearchTests {
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("3"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("3"));
|
||||||
assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0));
|
assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0));
|
||||||
|
|
||||||
logger.info("running doc['num1'].value > param1");
|
logger.info(" --> running doc['num1'].value > param1");
|
||||||
response = client.prepareSearch()
|
response = client().prepareSearch()
|
||||||
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1)))
|
.setQuery(filteredQuery(matchAllQuery(), scriptFilter("doc['num1'].value > param1").lang("js").addParam("param1", -1)))
|
||||||
.addSort("num1", SortOrder.ASC)
|
.addSort("num1", SortOrder.ASC)
|
||||||
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
.addScriptField("sNum1", "js", "doc['num1'].value", null)
|
||||||
|
@ -129,16 +94,16 @@ public class JavaScriptScriptSearchTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptFieldUsingSource() throws Exception {
|
public void testScriptFieldUsingSource() throws Exception {
|
||||||
client.admin().indices().prepareCreate("test").execute().actionGet();
|
wipeIndices("test");
|
||||||
client.prepareIndex("test", "type1", "1")
|
createIndex("test");
|
||||||
.setSource(jsonBuilder().startObject()
|
index("test", "type1", "1",
|
||||||
|
jsonBuilder().startObject()
|
||||||
.startObject("obj1").field("test", "something").endObject()
|
.startObject("obj1").field("test", "something").endObject()
|
||||||
.startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject()
|
.startObject("obj2").startArray("arr2").value("arr_value1").value("arr_value2").endArray().endObject()
|
||||||
.endObject())
|
.endObject());
|
||||||
.execute().actionGet();
|
refresh();
|
||||||
client.admin().indices().refresh(refreshRequest()).actionGet();
|
|
||||||
|
|
||||||
SearchResponse response = client.prepareSearch()
|
SearchResponse response = client().prepareSearch()
|
||||||
.setQuery(matchAllQuery())
|
.setQuery(matchAllQuery())
|
||||||
.addField("_source.obj1") // we also automatically detect _source in fields
|
.addField("_source.obj1") // we also automatically detect _source in fields
|
||||||
.addScriptField("s_obj1", "js", "_source.obj1", null)
|
.addScriptField("s_obj1", "js", "_source.obj1", null)
|
||||||
|
@ -169,99 +134,95 @@ public class JavaScriptScriptSearchTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomScriptBoost() throws Exception {
|
public void testCustomScriptBoost() throws Exception {
|
||||||
// execute a search before we create an index
|
wipeIndices("test");
|
||||||
try {
|
createIndex("test");
|
||||||
client.prepareSearch().setQuery(termQuery("test", "value")).execute().actionGet();
|
index("test", "type1", "1", jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject());
|
||||||
assert false : "should fail";
|
index("test", "type1", "2", jsonBuilder().startObject().field("test", "value beck").field("num1", 2.0f).endObject());
|
||||||
} catch (Exception e) {
|
refresh();
|
||||||
// ignore, no indices
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
client.prepareSearch("test").setQuery(termQuery("test", "value")).execute().actionGet();
|
|
||||||
assert false : "should fail";
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore, no indices
|
|
||||||
}
|
|
||||||
|
|
||||||
client.admin().indices().create(createIndexRequest("test")).actionGet();
|
|
||||||
client.index(indexRequest("test").type("type1").id("1")
|
|
||||||
.source(jsonBuilder().startObject().field("test", "value beck").field("num1", 1.0f).endObject())).actionGet();
|
|
||||||
client.index(indexRequest("test").type("type1").id("2")
|
|
||||||
.source(jsonBuilder().startObject().field("test", "value check").field("num1", 2.0f).endObject())).actionGet();
|
|
||||||
client.admin().indices().refresh(refreshRequest()).actionGet();
|
|
||||||
|
|
||||||
logger.info("--- QUERY_THEN_FETCH");
|
logger.info("--- QUERY_THEN_FETCH");
|
||||||
|
|
||||||
logger.info("running doc['num1'].value");
|
logger.info(" --> running doc['num1'].value");
|
||||||
SearchResponse response = client.search(searchRequest()
|
SearchResponse response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
||||||
|
|
||||||
logger.info("running -doc['num1'].value");
|
logger.info(" --> running -doc['num1'].value");
|
||||||
response = client.search(searchRequest()
|
response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("2"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("2"));
|
||||||
|
|
||||||
|
|
||||||
logger.info("running pow(doc['num1'].value, 2)");
|
logger.info(" --> running pow(doc['num1'].value, 2)");
|
||||||
response = client.search(searchRequest()
|
response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
||||||
|
|
||||||
logger.info("running max(doc['num1'].value, 1)");
|
logger.info(" --> running max(doc['num1'].value, 1)");
|
||||||
response = client.search(searchRequest()
|
response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
||||||
|
|
||||||
logger.info("running doc['num1'].value * _score");
|
logger.info(" --> running doc['num1'].value * _score");
|
||||||
response = client.search(searchRequest()
|
response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
assertThat(response.getHits().getAt(0).id(), equalTo("2"));
|
||||||
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
assertThat(response.getHits().getAt(1).id(), equalTo("1"));
|
||||||
|
|
||||||
logger.info("running param1 * param2 * _score");
|
logger.info(" --> running param1 * param2 * _score");
|
||||||
response = client.search(searchRequest()
|
response = client().search(searchRequest()
|
||||||
.searchType(SearchType.QUERY_THEN_FETCH)
|
.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(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js")))
|
||||||
).actionGet();
|
).actionGet();
|
||||||
|
|
||||||
|
assertThat("Failures " + Arrays.toString(response.getShardFailures()), response.getShardFailures().length, equalTo(0));
|
||||||
|
|
||||||
assertThat(response.getHits().totalHits(), equalTo(2l));
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
||||||
logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
logger.info(" --> Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation());
|
||||||
logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
logger.info(" --> Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue