Throw an exception if a type's mapping root node is not equal to the type in question.
Also, fix all the problems it brought up in tests. Removed OverrideTypeMappingTests as it is no longer relevant. Better naming for the default percolator mapping and change it's content use _default_ as root node. Closes #4038
This commit is contained in:
parent
552852f299
commit
0ef2493b2c
|
@ -249,22 +249,26 @@ public class DocumentMapperParser extends AbstractIndexComponent {
|
|||
}
|
||||
int size = root.size();
|
||||
switch (size) {
|
||||
case 0:
|
||||
// if we don't have any keys throw an exception
|
||||
throw new MapperParsingException("malformed mapping no root object found");
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
// we always assume the first and single key is the mapping type root
|
||||
throw new MapperParsingException("mapping must have the `type` as the root object");
|
||||
case 0:
|
||||
// if we don't have any keys throw an exception
|
||||
throw new MapperParsingException("malformed mapping no root object found");
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
// we always assume the first and single key is the mapping type root
|
||||
throw new MapperParsingException("mapping must have the `type` as the root object");
|
||||
|
||||
}
|
||||
|
||||
String rootName = root.keySet().iterator().next();
|
||||
if (type == null) {
|
||||
type = rootName;
|
||||
} else if (!type.equals(rootName)) {
|
||||
// we always assume the first and single key is the mapping type root
|
||||
throw new MapperParsingException("mapping must have the `type` as the root object. Got [" + rootName + "], expected [" + type + "]");
|
||||
}
|
||||
|
||||
|
||||
return new Tuple<String, Map<String, Object>>(type, (Map<String, Object>) root.get(rootName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
private final boolean dynamic;
|
||||
|
||||
private volatile String defaultMappingSource;
|
||||
private volatile String percolatorMappingSource;
|
||||
private volatile String defaultPercolatorMappingSource;
|
||||
|
||||
private volatile Map<String, DocumentMapper> mappers = ImmutableMap.of();
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
}
|
||||
}
|
||||
|
||||
String percolatorMappingLocation = componentSettings.get("percolator_mapping_location");
|
||||
String percolatorMappingLocation = componentSettings.get("default_percolator_mapping_location");
|
||||
URL percolatorMappingUrl = null;
|
||||
if (percolatorMappingLocation != null) {
|
||||
try {
|
||||
|
@ -161,19 +161,19 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
try {
|
||||
percolatorMappingUrl = new File(percolatorMappingLocation).toURI().toURL();
|
||||
} catch (MalformedURLException e1) {
|
||||
throw new FailedToResolveConfigException("Failed to resolve percolator mapping location [" + defaultMappingLocation + "]");
|
||||
throw new FailedToResolveConfigException("Failed to resolve default percolator mapping location [" + percolatorMappingLocation + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (percolatorMappingUrl != null) {
|
||||
try {
|
||||
percolatorMappingSource = Streams.copyToString(new InputStreamReader(percolatorMappingUrl.openStream(), Charsets.UTF_8));
|
||||
defaultPercolatorMappingSource = Streams.copyToString(new InputStreamReader(percolatorMappingUrl.openStream(), Charsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
throw new MapperException("Failed to load default percolator mapping source from [" + percolatorMappingUrl + "]", e);
|
||||
}
|
||||
} else {
|
||||
percolatorMappingSource = "{\n" +
|
||||
" \"_percolator\":{\n" +
|
||||
defaultPercolatorMappingSource = "{\n" +
|
||||
" \"_default_\":{\n" +
|
||||
" \"_id\" : {\"index\": \"not_analyzed\"}," +
|
||||
" \"properties\" : {\n" +
|
||||
" \"query\" : {\n" +
|
||||
|
@ -188,7 +188,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}], default percolator mapping: location[{}], loaded_from[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, percolatorMappingLocation, percolatorMappingUrl);
|
||||
} else if (logger.isTraceEnabled()) {
|
||||
logger.trace("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}], default percolator mapping: location[{}], loaded_from[{}] and source[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, defaultMappingSource, percolatorMappingLocation, percolatorMappingUrl, percolatorMappingSource);
|
||||
logger.trace("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}], default percolator mapping: location[{}], loaded_from[{}] and source[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, defaultMappingSource, percolatorMappingLocation, percolatorMappingUrl, defaultPercolatorMappingSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
public DocumentMapper parse(String mappingType, String mappingSource, boolean applyDefault) throws MapperParsingException {
|
||||
String defaultMappingSource;
|
||||
if (PercolatorService.Constants.TYPE_NAME.equals(mappingType)) {
|
||||
defaultMappingSource = percolatorMappingSource;
|
||||
defaultMappingSource = defaultPercolatorMappingSource;
|
||||
} else {
|
||||
defaultMappingSource = this.defaultMappingSource;
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ import static org.hamcrest.Matchers.*;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
@ClusterScope(numNodes=0, scope=Scope.TEST)
|
||||
@ClusterScope(numNodes = 0, scope = Scope.TEST)
|
||||
public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest {
|
||||
|
||||
|
||||
|
||||
private ImmutableSettings.Builder settingsBuilder() {
|
||||
return ImmutableSettings.settingsBuilder().put("gateway.type", "local");
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest {
|
|||
public boolean clearData(String nodeName) {
|
||||
return firstNode.equals(nodeName);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
logger.info("Running Cluster Health (wait for the shards to startup)");
|
||||
|
@ -290,7 +290,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest {
|
|||
|
||||
logger.info("--> add some metadata, additional type and template");
|
||||
client.admin().indices().preparePutMapping("test").setType("type2")
|
||||
.setSource(jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", false).endObject().endObject().endObject())
|
||||
.setSource(jsonBuilder().startObject().startObject("type2").startObject("_source").field("enabled", false).endObject().endObject().endObject())
|
||||
.execute().actionGet();
|
||||
client.admin().indices().preparePutTemplate("template_1")
|
||||
.setTemplate("te*")
|
||||
|
@ -303,9 +303,9 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest {
|
|||
client.admin().indices().prepareAliases().addAlias("test", "test_alias", FilterBuilders.termFilter("field", "value")).execute().actionGet();
|
||||
logger.info("--> starting two nodes back, verifying we got the latest version");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
logger.info("--> running cluster_health (wait for the shards to startup)");
|
||||
|
@ -333,7 +333,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest {
|
|||
ImmutableSettings.Builder settings = settingsBuilder()
|
||||
.put("action.admin.cluster.node.shutdown.delay", "10ms")
|
||||
.put("gateway.recover_after_nodes", 4)
|
||||
|
||||
|
||||
.put(BalancedShardsAllocator.SETTING_THRESHOLD, 1.1f); // use less agressive settings
|
||||
|
||||
cluster().startNode(settings);
|
||||
|
|
|
@ -228,8 +228,8 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
public void getFieldsWithDifferentTypes() throws Exception {
|
||||
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.refresh_interval", -1))
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type").startObject("_source").field("enabled", true).endObject().endObject().endObject())
|
||||
.addMapping("type2", jsonBuilder().startObject().startObject("type")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", true).endObject().endObject().endObject())
|
||||
.addMapping("type2", jsonBuilder().startObject().startObject("type2")
|
||||
.startObject("_source").field("enabled", false).endObject()
|
||||
.startObject("properties")
|
||||
.startObject("str").field("type", "string").field("store", "yes").endObject()
|
||||
|
@ -397,12 +397,12 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testThatGetFromTranslogShouldWorkWithExclude() throws Exception {
|
||||
String index = "test";
|
||||
String index = "test";
|
||||
String type = "type1";
|
||||
|
||||
String mapping = jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("source_excludes")
|
||||
.startObject(type)
|
||||
.startObject("_source")
|
||||
.array("excludes", "excluded")
|
||||
.endObject()
|
||||
|
@ -432,12 +432,12 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testThatGetFromTranslogShouldWorkWithInclude() throws Exception {
|
||||
String index = "test";
|
||||
String index = "test";
|
||||
String type = "type1";
|
||||
|
||||
String mapping = jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("source_excludes")
|
||||
.startObject(type)
|
||||
.startObject("_source")
|
||||
.array("includes", "included")
|
||||
.endObject()
|
||||
|
@ -468,12 +468,12 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testThatGetFromTranslogShouldWorkWithIncludeExcludeAndFields() throws Exception {
|
||||
String index = "test";
|
||||
String index = "test";
|
||||
String type = "type1";
|
||||
|
||||
String mapping = jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("source_excludes")
|
||||
.startObject(type)
|
||||
.startObject("_source")
|
||||
.array("includes", "included")
|
||||
.array("exlcudes", "excluded")
|
||||
|
@ -552,7 +552,8 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
try {
|
||||
client().prepareGet("test", "type1", "1").setVersion(2).execute().actionGet();
|
||||
assert false;
|
||||
} catch (VersionConflictEngineException e) {}
|
||||
} catch (VersionConflictEngineException e) {
|
||||
}
|
||||
|
||||
// From Lucene index:
|
||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
||||
|
@ -571,7 +572,8 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
try {
|
||||
client().prepareGet("test", "type1", "1").setVersion(2).setRealtime(false).execute().actionGet();
|
||||
assert false;
|
||||
} catch (VersionConflictEngineException e) {}
|
||||
} catch (VersionConflictEngineException e) {
|
||||
}
|
||||
|
||||
logger.info("--> index doc 1 again, so increasing the version");
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2").execute().actionGet();
|
||||
|
@ -587,7 +589,8 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
try {
|
||||
client().prepareGet("test", "type1", "1").setVersion(1).execute().actionGet();
|
||||
assert false;
|
||||
} catch (VersionConflictEngineException e) {}
|
||||
} catch (VersionConflictEngineException e) {
|
||||
}
|
||||
|
||||
response = client().prepareGet("test", "type1", "1").setVersion(2).execute().actionGet();
|
||||
assertThat(response.isExists(), equalTo(true));
|
||||
|
@ -606,7 +609,8 @@ public class GetActionTests extends AbstractIntegrationTest {
|
|||
try {
|
||||
client().prepareGet("test", "type1", "1").setVersion(1).setRealtime(false).execute().actionGet();
|
||||
assert false;
|
||||
} catch (VersionConflictEngineException e) {}
|
||||
} catch (VersionConflictEngineException e) {
|
||||
}
|
||||
|
||||
response = client().prepareGet("test", "type1", "1").setVersion(2).setRealtime(false).execute().actionGet();
|
||||
assertThat(response.isExists(), equalTo(true));
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.mapper.overridetype;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperTestUtils;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OverrideTypeMappingTests extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
public void testOverrideType() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
.startObject("_source").field("enabled", false).endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper mapper = MapperTestUtils.newParser().parse("my_type", mapping);
|
||||
assertThat(mapper.type(), equalTo("my_type"));
|
||||
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
|
||||
|
||||
mapper = MapperTestUtils.newParser().parse(mapping);
|
||||
assertThat(mapper.type(), equalTo("type"));
|
||||
assertThat(mapper.sourceMapper().enabled(), equalTo(false));
|
||||
}
|
||||
}
|
|
@ -150,14 +150,14 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
|
|||
// all is well
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultMappingAndWithMappingOverride() throws Exception {
|
||||
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING)
|
||||
.startObject("_source").field("enabled", false).endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type")
|
||||
.startObject("_source").field("enabled", true).endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
|
@ -189,7 +189,7 @@ public class DefaultSourceMappingTests extends ElasticsearchTestCase {
|
|||
MapperService mapperService = MapperTestUtils.newMapperService();
|
||||
mapperService.merge(MapperService.DEFAULT_MAPPING, defaultMapping, true);
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type")
|
||||
.startObject("_source").field("enabled", true).endObject()
|
||||
.endObject().endObject().string();
|
||||
mapperService.merge("my_type", mapping, true);
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
@ -42,22 +44,27 @@ public class SimpleGetMappingsTests extends AbstractIntegrationTest {
|
|||
assertThat(response.mappings().get("index").size(), equalTo(0));
|
||||
}
|
||||
|
||||
|
||||
private XContentBuilder getMappingForType(String type) throws IOException {
|
||||
return jsonBuilder().startObject().startObject(type).startObject("properties")
|
||||
.startObject("field1").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void simpleGetMappings() throws Exception {
|
||||
XContentBuilder mapping = jsonBuilder().startObject().startObject("properties")
|
||||
.startObject("field1").field("type", "string").endObject()
|
||||
.endObject().endObject();
|
||||
client().admin().indices().prepareCreate("indexa")
|
||||
.addMapping("typeA", mapping)
|
||||
.addMapping("typeB", mapping)
|
||||
.addMapping("Atype", mapping)
|
||||
.addMapping("Btype", mapping)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB"))
|
||||
.addMapping("Atype", getMappingForType("Atype"))
|
||||
.addMapping("Btype", getMappingForType("Btype"))
|
||||
.execute().actionGet();
|
||||
client().admin().indices().prepareCreate("indexb")
|
||||
.addMapping("typeA", mapping)
|
||||
.addMapping("typeB", mapping)
|
||||
.addMapping("Atype", mapping)
|
||||
.addMapping("Btype", mapping)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB"))
|
||||
.addMapping("Atype", getMappingForType("Atype"))
|
||||
.addMapping("Btype", getMappingForType("Btype"))
|
||||
.execute().actionGet();
|
||||
|
||||
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
|
@ -132,4 +139,5 @@ public class SimpleGetMappingsTests extends AbstractIntegrationTest {
|
|||
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
|
||||
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.*;
|
|||
|
||||
/**
|
||||
*/
|
||||
@ClusterScope(scope=Scope.TEST)
|
||||
@ClusterScope(scope = Scope.TEST)
|
||||
public class TTLPercolatorTests extends AbstractIntegrationTest {
|
||||
|
||||
private static final long PURGE_INTERVAL = 200;
|
||||
|
@ -38,15 +38,20 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
|||
client.admin().indices().prepareDelete().execute().actionGet();
|
||||
ensureGreen();
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator")
|
||||
String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator")
|
||||
.startObject("_ttl").field("enabled", true).endObject()
|
||||
.startObject("_timestamp").field("enabled", true).endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
String typeMapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("_ttl").field("enabled", true).endObject()
|
||||
.startObject("_timestamp").field("enabled", true).endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
client.admin().indices().prepareCreate("test")
|
||||
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
|
||||
.addMapping("_percolator", mapping)
|
||||
.addMapping("type1", mapping)
|
||||
.addMapping("_percolator", precolatorMapping)
|
||||
.addMapping("type1", typeMapping)
|
||||
.execute().actionGet();
|
||||
ensureGreen();
|
||||
|
||||
|
@ -70,12 +75,12 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
|||
PercolateResponse percolateResponse = client.preparePercolate()
|
||||
.setIndices("test").setDocumentType("type1")
|
||||
.setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("doc")
|
||||
.field("field1", "value1")
|
||||
.endObject()
|
||||
.endObject()
|
||||
).execute().actionGet();
|
||||
.startObject()
|
||||
.startObject("doc")
|
||||
.field("field1", "value1")
|
||||
.endObject()
|
||||
.endObject()
|
||||
).execute().actionGet();
|
||||
assertNoFailures(percolateResponse);
|
||||
if (percolateResponse.getMatches().length == 0) {
|
||||
// OK, ttl + purgeInterval has passed (slow machine or many other tests were running at the same time
|
||||
|
@ -111,12 +116,12 @@ public class TTLPercolatorTests extends AbstractIntegrationTest {
|
|||
percolateResponse = client.preparePercolate()
|
||||
.setIndices("test").setDocumentType("type1")
|
||||
.setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("doc")
|
||||
.field("field1", "value1")
|
||||
.endObject()
|
||||
.endObject()
|
||||
).execute().actionGet();
|
||||
.startObject()
|
||||
.startObject("doc")
|
||||
.field("field1", "value1")
|
||||
.endObject()
|
||||
.endObject()
|
||||
).execute().actionGet();
|
||||
assertNoFailures(percolateResponse);
|
||||
assertThat(percolateResponse.getMatches(), emptyArray());
|
||||
}
|
||||
|
|
|
@ -75,14 +75,14 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
client().admin()
|
||||
.indices()
|
||||
.preparePutMapping("test")
|
||||
.setType("grandchild")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "child").endObject()
|
||||
jsonBuilder().startObject().startObject("grandchild").startObject("_parent").field("type", "child").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
client().prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1").execute().actionGet();
|
||||
|
@ -145,7 +145,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("test")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "foo").endObject().endObject()
|
||||
jsonBuilder().startObject().startObject("test").startObject("_parent").field("type", "foo").endObject().endObject()
|
||||
.endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -171,7 +171,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -291,7 +291,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
assertThat(indicesStatsResponse.getTotal().getIdCache().getMemorySizeInBytes(), equalTo(0l));
|
||||
|
||||
// Now add mapping + children
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
@ -337,7 +337,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -381,7 +381,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
Map<String, Set<String>> parentToChildren = newHashMap();
|
||||
|
@ -441,7 +441,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data with flushes, so we have many segments
|
||||
|
@ -549,7 +549,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data with flushes, so we have many segments
|
||||
|
@ -657,7 +657,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -704,7 +704,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -774,7 +774,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -814,7 +814,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -845,7 +845,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
int numberOfParents = 4;
|
||||
|
@ -890,7 +890,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
client().prepareIndex("test", "parent", "1").setSource("p_field", 1).execute().actionGet();
|
||||
|
@ -924,7 +924,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
String parentId = "p1";
|
||||
|
@ -964,7 +964,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
String parentId = "p1";
|
||||
|
@ -1008,11 +1008,11 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.prepareCreate("test")
|
||||
.addMapping(
|
||||
"child",
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject())
|
||||
.addMapping(
|
||||
"child1",
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child1").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject())
|
||||
.setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0))
|
||||
.execute().actionGet();
|
||||
|
@ -1116,7 +1116,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.setSource("c_field1", 1, "c_field2", 1).setParent("2"));
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("9").setIndex("test")
|
||||
.setSource("c_field1", 1, "c_field2", 1).setParent("p")); // why
|
||||
// "p"????
|
||||
// "p"????
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("10").setIndex("test")
|
||||
.setSource("c_field1", 1, "c_field2", 1).setParent("2"));
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("11").setIndex("test")
|
||||
|
@ -1134,7 +1134,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.setSource("c_field1", 1, "c_field2", 1, "c_field3", 1).setParent("3"));
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("15").setIndex("test")
|
||||
.setSource("c_field1", 1, "c_field2", 2, "c_field3", 2).setParent("3")); // why
|
||||
// "p"????
|
||||
// "p"????
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("16").setIndex("test")
|
||||
.setSource("c_field1", 1, "c_field2", 2, "c_field3", 3).setParent("3"));
|
||||
indexBuilders.add(client().prepareIndex().setType("child").setId("17").setIndex("test")
|
||||
|
@ -1155,11 +1155,11 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.prepareCreate("test")
|
||||
.addMapping(
|
||||
"child",
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject())
|
||||
.addMapping(
|
||||
"child1",
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child1").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject())
|
||||
.setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0))
|
||||
.execute().actionGet();
|
||||
|
@ -1296,7 +1296,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
client().prepareIndex("test", "parent", "1").setSource("p_field", 1).execute().actionGet();
|
||||
|
@ -1333,7 +1333,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -1350,7 +1350,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
}
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
||||
SearchType[] searchTypes = new SearchType[] { SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH };
|
||||
SearchType[] searchTypes = new SearchType[]{SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH};
|
||||
for (SearchType searchType : searchTypes) {
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSearchType(searchType)
|
||||
.setQuery(hasChildQuery("child", prefixQuery("c_field", "c")).scoreType("max")).addSort("p_field", SortOrder.ASC)
|
||||
|
@ -1401,7 +1401,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -1475,7 +1475,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject()
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// index simple data
|
||||
|
@ -1518,7 +1518,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.preparePutMapping("test")
|
||||
.setType("child2")
|
||||
.setSource(
|
||||
jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent2").endObject()
|
||||
jsonBuilder().startObject().startObject("child2").startObject("_parent").field("type", "parent2").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
// test term filter
|
||||
|
@ -1587,7 +1587,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.put("index.number_of_replicas", 0)
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
@ -1632,7 +1632,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.put("index.refresh_interval", "-1")
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
@ -1678,7 +1678,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.put("index.refresh_interval", "-1")
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
@ -1734,7 +1734,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.put("index.refresh_interval", "-1")
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
@ -1848,7 +1848,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child1").setSource(
|
||||
jsonBuilder().startObject().startObject("type").endObject().endObject()
|
||||
jsonBuilder().startObject().startObject("child1").endObject().endObject()
|
||||
).execute().actionGet();
|
||||
|
||||
client().prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1", "_parent", "bla").execute().actionGet();
|
||||
|
@ -1883,13 +1883,13 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
assertThat(putMappingResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet();
|
||||
Map<String, Object> mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap();
|
||||
Map<String, Object> mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap();
|
||||
assertThat(mapping.size(), equalTo(1));
|
||||
assertThat(mapping.get("properties"), notNullValue());
|
||||
|
||||
try {
|
||||
// Adding _parent metadata field to existing mapping is prohibited:
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
fail();
|
||||
|
@ -1908,7 +1908,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest {
|
|||
.put("index.number_of_replicas", 0)
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type")
|
||||
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child")
|
||||
.startObject("_parent").field("type", "parent").endObject()
|
||||
.endObject().endObject()).execute().actionGet();
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ import static org.hamcrest.Matchers.*;
|
|||
*
|
||||
*/
|
||||
public class SearchFieldsTests extends AbstractIntegrationTest {
|
||||
|
||||
|
||||
@Override
|
||||
public Settings getSettings() {
|
||||
return randomSettingsBuilder()
|
||||
|
@ -62,7 +62,7 @@ public class SearchFieldsTests extends AbstractIntegrationTest {
|
|||
createIndex("test");
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("field1").field("type", "string").field("store", "yes").endObject()
|
||||
.startObject("field2").field("type", "string").field("store", "no").endObject()
|
||||
.startObject("field3").field("type", "string").field("store", "yes").endObject()
|
||||
|
@ -119,7 +119,7 @@ public class SearchFieldsTests extends AbstractIntegrationTest {
|
|||
createIndex("test");
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("num1").field("type", "double").field("store", "yes").endObject()
|
||||
.endObject().endObject().endObject().string();
|
||||
|
||||
|
@ -272,7 +272,7 @@ public class SearchFieldsTests extends AbstractIntegrationTest {
|
|||
createIndex("test");
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("_source").field("enabled", false).endObject()
|
||||
.startObject("byte_field").field("type", "byte").field("store", "yes").endObject()
|
||||
.startObject("short_field").field("type", "short").field("store", "yes").endObject()
|
||||
|
|
|
@ -119,7 +119,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertTrue("wrong exception message " + e.getMessage(), e.getMessage().endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test // see #3521
|
||||
public void testConstantScoreQuery() throws Exception {
|
||||
Random random = getRandom();
|
||||
|
@ -132,29 +132,29 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
for (SearchHit searchHit : hits) {
|
||||
assertThat(searchHit.getScore(), equalTo(1.0f));
|
||||
}
|
||||
|
||||
|
||||
searchResponse = client().prepareSearch("test").setQuery(
|
||||
QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get();
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get();
|
||||
hits = searchResponse.getHits();
|
||||
assertThat(hits.totalHits(), equalTo(2l));
|
||||
assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score()));
|
||||
|
||||
|
||||
client().prepareSearch("test").setQuery(QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat())).get();
|
||||
hits = searchResponse.getHits();
|
||||
assertThat(hits.totalHits(), equalTo(2l));
|
||||
assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score()));
|
||||
|
||||
|
||||
searchResponse = client().prepareSearch("test").setQuery(
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat()))))).get();
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat()))))).get();
|
||||
hits = searchResponse.getHits();
|
||||
assertThat(hits.totalHits(), equalTo(2l));
|
||||
assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score()));
|
||||
for (SearchHit searchHit : hits) {
|
||||
assertThat(searchHit.getScore(), equalTo(1.0f));
|
||||
}
|
||||
|
||||
|
||||
int num = atLeast(100);
|
||||
IndexRequestBuilder[] builders = new IndexRequestBuilder[num];
|
||||
for (int i = 0; i < builders.length; i++) {
|
||||
|
@ -175,13 +175,13 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
if (random.nextBoolean()) {
|
||||
searchResponse = client().prepareSearch("test_1").setQuery(
|
||||
QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
|
||||
QueryBuilders.constantScoreQuery(matchQuery).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat())))).setSize(num).get();
|
||||
hits = searchResponse.getHits();
|
||||
QueryBuilders.constantScoreQuery(matchQuery).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat())))).setSize(num).get();
|
||||
hits = searchResponse.getHits();
|
||||
} else {
|
||||
FilterBuilder filter = FilterBuilders.queryFilter(matchQuery);
|
||||
searchResponse = client().prepareSearch("test_1").setQuery(
|
||||
QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
|
||||
QueryBuilders.constantScoreQuery(filter).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat())))).setSize(num).get();
|
||||
QueryBuilders.constantScoreQuery(filter).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat())))).setSize(num).get();
|
||||
hits = searchResponse.getHits();
|
||||
}
|
||||
assertThat(hits.totalHits(), equalTo(totalHits));
|
||||
|
@ -193,13 +193,13 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test // see #3521
|
||||
public void testAllDocsQueryString() throws InterruptedException, ExecutionException {
|
||||
client().admin().indices().prepareCreate("test")
|
||||
.setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_replicas", 0)).execute().actionGet();
|
||||
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("foo", "bar"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("foo", "bar")
|
||||
client().prepareIndex("test", "type1", "2").setSource("foo", "bar")
|
||||
);
|
||||
int iters = atLeast(100);
|
||||
for (int i = 0; i < iters; i++) {
|
||||
|
@ -208,15 +208,15 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
.execute().actionGet();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must(
|
||||
QueryBuilders.constantScoreQuery(QueryBuilders.matchAllQuery())))
|
||||
.execute().actionGet();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(Math.sqrt(2), 0.1));
|
||||
assertThat((double)searchResponse.getHits().getAt(1).score(),closeTo(Math.sqrt(2), 0.1));
|
||||
assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(Math.sqrt(2), 0.1));
|
||||
assertThat((double) searchResponse.getHits().getAt(1).score(), closeTo(Math.sqrt(2), 0.1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -881,7 +881,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
float boost = 10.0f;
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
||||
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("important", "phrase match", "less_important", "nothing important"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match")
|
||||
client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match")
|
||||
);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
|
@ -891,7 +891,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important").useDisMax(false))
|
||||
|
@ -900,9 +900,9 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpecialRangeSyntaxInQueryString() {
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
||||
|
@ -957,10 +957,10 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testEmptyTermsFilter() throws Exception {
|
||||
assertAcked(prepareCreate("test").addMapping("type",
|
||||
assertAcked(prepareCreate("test").addMapping("type",
|
||||
jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("term").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("term").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type", "1").setSource("term", "1").execute().actionGet();
|
||||
client().prepareIndex("test", "type", "2").setSource("term", "2").execute().actionGet();
|
||||
|
@ -982,19 +982,19 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testTermsLookupFilter() throws Exception {
|
||||
assertAcked(prepareCreate("lookup").addMapping("type",
|
||||
assertAcked(prepareCreate("lookup").addMapping("type",
|
||||
jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("terms").field("type", "string").endObject()
|
||||
.startObject("other").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
assertAcked(prepareCreate("lookup2").addMapping("type",
|
||||
.startObject("terms").field("type", "string").endObject()
|
||||
.startObject("other").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
assertAcked(prepareCreate("lookup2").addMapping("type",
|
||||
jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("arr").startObject("properties").startObject("term").field("type", "string")
|
||||
.endObject().endObject().endObject().endObject().endObject().endObject()));
|
||||
assertAcked(prepareCreate("test").addMapping("type",
|
||||
.startObject("arr").startObject("properties").startObject("term").field("type", "string")
|
||||
.endObject().endObject().endObject().endObject().endObject().endObject()));
|
||||
assertAcked(prepareCreate("test").addMapping("type",
|
||||
jsonBuilder().startObject().startObject("type").startObject("properties")
|
||||
.startObject("term").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("term").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("lookup", "type", "1").setSource("terms", new String[]{"1", "3"}).execute().actionGet();
|
||||
client().prepareIndex("lookup", "type", "2").setSource("terms", new String[]{"2"}).execute().actionGet();
|
||||
|
@ -1201,7 +1201,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testNumericTermsAndRanges() throws Exception {
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1))
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1))
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("num_byte").field("type", "byte").endObject()
|
||||
.startObject("num_short").field("type", "short").endObject()
|
||||
|
@ -1330,7 +1330,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testNumericRangeFilter_2826() throws Exception {
|
||||
client().admin().indices().prepareCreate("test").setSettings(
|
||||
client().admin().indices().prepareCreate("test").setSettings(
|
||||
ImmutableSettings.settingsBuilder()
|
||||
.put("index.number_of_shards", 1)
|
||||
.put("index.number_of_replicas", 0)
|
||||
|
@ -1407,7 +1407,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
|
||||
@Test // see #2926
|
||||
public void testMustNot() throws ElasticSearchException, IOException {
|
||||
client().admin().indices().prepareCreate("test").setSettings(
|
||||
client().admin().indices().prepareCreate("test").setSettings(
|
||||
ImmutableSettings.settingsBuilder()
|
||||
.put("index.number_of_shards", 2)
|
||||
.put("index.number_of_replicas", 0)
|
||||
|
@ -1581,41 +1581,41 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
.put("index.number_of_replicas", 0)
|
||||
).addMapping("s", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("s")
|
||||
.startObject("_routing")
|
||||
.field("required", true)
|
||||
.field("path", "bs")
|
||||
.endObject()
|
||||
.startObject("properties")
|
||||
.startObject("online")
|
||||
.field("type", "boolean")
|
||||
.endObject()
|
||||
.startObject("ts")
|
||||
.field("type", "date")
|
||||
.field("ignore_malformed", false)
|
||||
.field("format", "dateOptionalTime")
|
||||
.endObject()
|
||||
.startObject("bs")
|
||||
.field("type", "string")
|
||||
.field("index", "not_analyzed")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("s")
|
||||
.startObject("_routing")
|
||||
.field("required", true)
|
||||
.field("path", "bs")
|
||||
.endObject()
|
||||
.startObject("properties")
|
||||
.startObject("online")
|
||||
.field("type", "boolean")
|
||||
.endObject()
|
||||
.startObject("ts")
|
||||
.field("type", "date")
|
||||
.field("ignore_malformed", false)
|
||||
.field("format", "dateOptionalTime")
|
||||
.endObject()
|
||||
.startObject("bs")
|
||||
.field("type", "string")
|
||||
.field("index", "not_analyzed")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject())
|
||||
.addMapping("bs", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("s")
|
||||
.startObject("properties")
|
||||
.startObject("online")
|
||||
.field("type", "boolean")
|
||||
.endObject()
|
||||
.startObject("ts")
|
||||
.field("type", "date")
|
||||
.field("ignore_malformed", false)
|
||||
.field("format", "dateOptionalTime")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("bs")
|
||||
.startObject("properties")
|
||||
.startObject("online")
|
||||
.field("type", "boolean")
|
||||
.endObject()
|
||||
.startObject("ts")
|
||||
.field("type", "date")
|
||||
.field("ignore_malformed", false)
|
||||
.field("format", "dateOptionalTime")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject())
|
||||
.execute().actionGet();
|
||||
ensureGreen();
|
||||
|
@ -1689,7 +1689,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertHitCount(client().prepareSearch("test").setQuery(queryString("/value[01]/").field("field1").field("field2")).get(), 1);
|
||||
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:/value[01]/")).get(), 1);
|
||||
}
|
||||
|
||||
|
||||
// see #3881 - for extensive description of the issue
|
||||
@Test
|
||||
public void testMatchQueryWithSynonyms() throws IOException {
|
||||
|
@ -1700,18 +1700,18 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
.put("index.analysis.analyzer.index.tokenizer", "standard")
|
||||
.put("index.analysis.analyzer.index.filter", "lowercase")
|
||||
.put("index.analysis.analyzer.search.type", "custom")
|
||||
.put("index.analysis.analyzer.search.tokenizer", "standard")
|
||||
.put("index.analysis.analyzer.search.tokenizer", "standard")
|
||||
|
||||
.putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym")
|
||||
.put("index.analysis.filter.synonym.type", "synonym")
|
||||
.putArray("index.analysis.filter.synonym.synonyms", "fast, quick"));
|
||||
|
||||
|
||||
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test")
|
||||
.startObject("properties")
|
||||
.startObject("text")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject();
|
||||
|
@ -1728,7 +1728,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertHitCount(searchResponse, 1);
|
||||
searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fast").operator(MatchQueryBuilder.Operator.AND)).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
|
||||
|
||||
client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject()
|
||||
.field("text", "fast brown fox")
|
||||
.endObject())
|
||||
|
@ -1739,7 +1739,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "quick brown").operator(MatchQueryBuilder.Operator.AND)).get();
|
||||
assertHitCount(searchResponse, 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchQueryWithStackedStems() throws IOException {
|
||||
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(settingsBuilder()
|
||||
|
@ -1753,13 +1753,13 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
.putArray("index.analysis.analyzer.search.filter", "lowercase", "keyword_repeat", "porterStem", "unique_stem")
|
||||
.put("index.analysis.filter.unique_stem.type", "unique")
|
||||
.put("index.analysis.filter.unique_stem.only_on_same_position", true));
|
||||
|
||||
|
||||
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test")
|
||||
.startObject("properties")
|
||||
.startObject("text")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject();
|
||||
|
@ -1772,7 +1772,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fox runs").operator(MatchQueryBuilder.Operator.AND)).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
|
||||
|
||||
client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject()
|
||||
.field("text", "run fox run")
|
||||
.endObject())
|
||||
|
@ -1781,7 +1781,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fox runs").operator(MatchQueryBuilder.Operator.AND)).get();
|
||||
assertHitCount(searchResponse, 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testQueryStringWithSynonyms() throws IOException {
|
||||
CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(settingsBuilder()
|
||||
|
@ -1791,18 +1791,18 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
.put("index.analysis.analyzer.index.tokenizer", "standard")
|
||||
.put("index.analysis.analyzer.index.filter", "lowercase")
|
||||
.put("index.analysis.analyzer.search.type", "custom")
|
||||
.put("index.analysis.analyzer.search.tokenizer", "standard")
|
||||
.put("index.analysis.analyzer.search.tokenizer", "standard")
|
||||
|
||||
.putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym")
|
||||
.put("index.analysis.filter.synonym.type", "synonym")
|
||||
.putArray("index.analysis.filter.synonym.synonyms", "fast, quick"));
|
||||
|
||||
|
||||
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test")
|
||||
.startObject("properties")
|
||||
.startObject("text")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.field("type", "string")
|
||||
.field("index_analyzer", "index")
|
||||
.field("search_analyzer", "search")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject();
|
||||
|
@ -1819,7 +1819,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
|||
assertHitCount(searchResponse, 1);
|
||||
searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryString("fast").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
|
||||
|
||||
client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject()
|
||||
.field("text", "fast brown fox")
|
||||
.endObject())
|
||||
|
|
Loading…
Reference in New Issue