GET operations should not extract fields from _source. #20158

This makes GET operations more consistent with `_search` operations which expect
`(stored_)fields` to work on stored fields and source filtering to work on the
`_source` field. This is now possible thanks to the fact that GET operations
do not read from the translog anymore (#20102) and also allows to get rid of
`FieldMapper#isGenerated`.

The `_termvectors` API (and thus more_like_this too) was relying on the fact
that GET operations would extract fields from either stored fields or the source
so the logic to do this that used to exist in `ShardGetService` has been moved
to `TermVectorsService`. It would be nice that term vectors do not rely on this,
but this does not seem to be a low hanging fruit.
This commit is contained in:
Adrien Grand 2016-08-25 11:42:27 +02:00
parent 6fe9ae29ea
commit 3ed0da5a58
17 changed files with 133 additions and 134 deletions

View File

@ -41,28 +41,19 @@ import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParentFieldMapper;
import org.elasticsearch.index.mapper.RoutingFieldMapper;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.TTLFieldMapper;
import org.elasticsearch.index.mapper.TimestampFieldMapper;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.index.shard.AbstractIndexShardComponent;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.ParentFieldSubFetchPhase;
import org.elasticsearch.search.lookup.LeafSearchLookup;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
@ -218,41 +209,14 @@ public final class ShardGetService extends AbstractIndexShardComponent {
fields.put(ParentFieldMapper.NAME, new GetField(ParentFieldMapper.NAME, Collections.singletonList(parentId)));
}
// now, go and do the script thingy if needed
if (gFields != null && gFields.length > 0) {
SearchLookup searchLookup = null;
for (String field : gFields) {
Object value = null;
FieldMapper fieldMapper = docMapper.mappers().smartNameFieldMapper(field);
if (fieldMapper == null) {
if (docMapper.objectMappers().get(field) != null) {
// Only fail if we know it is a object field, missing paths / fields shouldn't fail.
throw new IllegalArgumentException("field [" + field + "] isn't a leaf field");
}
} else if (!fieldMapper.fieldType().stored() && !fieldMapper.isGenerated()) {
if (searchLookup == null) {
searchLookup = new SearchLookup(mapperService, null, new String[]{type});
LeafSearchLookup leafSearchLookup = searchLookup.getLeafSearchLookup(docIdAndVersion.context);
searchLookup.source().setSource(source);
leafSearchLookup.setDocument(docIdAndVersion.docId);
}
List<Object> values = searchLookup.source().extractRawValues(field);
if (values.isEmpty() == false) {
value = values;
}
}
if (value != null) {
if (fields == null) {
fields = new HashMap<>(2);
}
if (value instanceof List) {
fields.put(field, new GetField(field, (List) value));
} else {
fields.put(field, new GetField(field, Collections.singletonList(value)));
}
}
}
}

View File

@ -291,8 +291,4 @@ public class AllFieldMapper extends MetadataFieldMapper {
super.doMerge(mergeWith, updateAllTypes);
}
@Override
public boolean isGenerated() {
return true;
}
}

View File

@ -660,14 +660,4 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
}
}
/**
* Fields might not be available before indexing, for example _all, token_count,...
* When get is called and these fields are requested, this case needs special treatment.
*
* @return If the field is available before indexing or not.
*/
public boolean isGenerated() {
return false;
}
}

View File

@ -289,8 +289,4 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper {
return builder;
}
@Override
public boolean isGenerated() {
return true;
}
}

View File

@ -187,9 +187,4 @@ public class LegacyTokenCountFieldMapper extends LegacyIntegerFieldMapper {
builder.field("analyzer", analyzer());
}
@Override
public boolean isGenerated() {
return true;
}
}

View File

@ -182,9 +182,4 @@ public class TokenCountFieldMapper extends FieldMapper {
builder.field("analyzer", analyzer());
}
@Override
public boolean isGenerated() {
return true;
}
}

View File

@ -35,6 +35,8 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.get.GetResult;
@ -44,6 +46,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.StringFieldMapper;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.mapper.Uid;
@ -55,8 +58,10 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@ -191,9 +196,11 @@ public class TermVectorsService {
}
/* generate term vectors from fetched document fields */
String[] getFields = validFields.toArray(new String[validFields.size() + 1]);
getFields[getFields.length - 1] = SourceFieldMapper.NAME;
GetResult getResult = indexShard.getService().get(
get, request.id(), request.type(), validFields.toArray(Strings.EMPTY_ARRAY), null);
Fields generatedTermVectors = generateTermVectors(indexShard, getResult.getFields().values(), request.offsets(), request.perFieldAnalyzer(), validFields);
get, request.id(), request.type(), getFields, null);
Fields generatedTermVectors = generateTermVectors(indexShard, getResult.sourceAsMap(), getResult.getFields().values(), request.offsets(), request.perFieldAnalyzer(), validFields);
/* merge with existing Fields */
if (termVectorsByField == null) {
@ -227,17 +234,31 @@ public class TermVectorsService {
return selectedFields;
}
private static Fields generateTermVectors(IndexShard indexShard, Collection<GetField> getFields, boolean withOffsets, @Nullable Map<String, String> perFieldAnalyzer, Set<String> fields) throws IOException {
/* store document in memory index */
MemoryIndex index = new MemoryIndex(withOffsets);
private static Fields generateTermVectors(IndexShard indexShard, Map<String, Object> source, Collection<GetField> getFields, boolean withOffsets, @Nullable Map<String, String> perFieldAnalyzer, Set<String> fields) throws IOException {
Map<String, Collection<Object>> values = new HashMap<>();
for (GetField getField : getFields) {
String field = getField.getName();
if (fields.contains(field) == false) {
// some fields are returned even when not asked for, eg. _timestamp
continue;
if (fields.contains(field)) { // some fields are returned even when not asked for, eg. _timestamp
values.put(field, getField.getValues());
}
}
if (source != null) {
for (String field : fields) {
if (values.containsKey(field) == false) {
List<Object> v = XContentMapValues.extractRawValues(field, source);
if (v.isEmpty() == false) {
values.put(field, v);
}
}
}
}
/* store document in memory index */
MemoryIndex index = new MemoryIndex(withOffsets);
for (Map.Entry<String, Collection<Object>> entry : values.entrySet()) {
String field = entry.getKey();
Analyzer analyzer = getAnalyzerAtField(indexShard, field, perFieldAnalyzer);
for (Object text : getField.getValues()) {
for (Object text : entry.getValue()) {
index.addField(field, text.toString(), analyzer);
}
}
@ -270,7 +291,7 @@ public class TermVectorsService {
String[] values = doc.getValues(field.name());
getFields.add(new GetField(field.name(), Arrays.asList((Object[]) values)));
}
return generateTermVectors(indexShard, getFields, request.offsets(), request.perFieldAnalyzer(), seenFields);
return generateTermVectors(indexShard, XContentHelper.convertToMap(parsedDocument.source(), true).v2(), getFields, request.offsets(), request.perFieldAnalyzer(), seenFields);
}
private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc) {

View File

@ -149,21 +149,21 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
assertThat(bulkResponse.getItems()[2].getResponse().getId(), equalTo("3"));
assertThat(bulkResponse.getItems()[2].getResponse().getVersion(), equalTo(2L));
GetResponse getResponse = client().prepareGet().setIndex("test").setType("type1").setId("1").setFields("field").execute()
GetResponse getResponse = client().prepareGet().setIndex("test").setType("type1").setId("1").execute()
.actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(2L));
assertThat(((Number) getResponse.getField("field").getValue()).longValue(), equalTo(2L));
assertThat(((Number) getResponse.getSource().get("field")).longValue(), equalTo(2L));
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("2").setFields("field").execute().actionGet();
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("2").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(2L));
assertThat(((Number) getResponse.getField("field").getValue()).longValue(), equalTo(3L));
assertThat(((Number) getResponse.getSource().get("field")).longValue(), equalTo(3L));
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("3").setFields("field1").execute().actionGet();
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("3").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(2L));
assertThat(getResponse.getField("field1").getValue().toString(), equalTo("test"));
assertThat(getResponse.getSource().get("field1").toString(), equalTo("test"));
bulkResponse = client()
.prepareBulk()
@ -185,18 +185,18 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
assertThat(bulkResponse.getItems()[2].getResponse().getIndex(), equalTo("test"));
assertThat(bulkResponse.getItems()[2].getResponse().getVersion(), equalTo(3L));
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("6").setFields("field").execute().actionGet();
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("6").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(1L));
assertThat(((Number) getResponse.getField("field").getValue()).longValue(), equalTo(0L));
assertThat(((Number) getResponse.getSource().get("field")).longValue(), equalTo(0L));
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("7").setFields("field").execute().actionGet();
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("7").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(false));
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("2").setFields("field").execute().actionGet();
getResponse = client().prepareGet().setIndex("test").setType("type1").setId("2").execute().actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(3L));
assertThat(((Number) getResponse.getField("field").getValue()).longValue(), equalTo(4L));
assertThat(((Number) getResponse.getSource().get("field")).longValue(), equalTo(4L));
}
public void testBulkVersioning() throws Exception {
@ -325,11 +325,11 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
assertThat(((UpdateResponse) response.getItems()[i].getResponse()).getGetResult().field("counter").getValue(), equalTo(1));
for (int j = 0; j < 5; j++) {
GetResponse getResponse = client().prepareGet("test", "type1", Integer.toString(i)).setFields("counter").execute()
GetResponse getResponse = client().prepareGet("test", "type1", Integer.toString(i)).execute()
.actionGet();
assertThat(getResponse.isExists(), equalTo(true));
assertThat(getResponse.getVersion(), equalTo(1L));
assertThat(((Number) getResponse.getField("counter").getValue()).longValue(), equalTo(1L));
assertThat(((Number) getResponse.getSource().get("counter")).longValue(), equalTo(1L));
}
}

View File

@ -37,7 +37,9 @@ public class AliasedIndexDocumentActionsIT extends DocumentActionsIT {
// ignore
}
logger.info("--> creating index test");
client().admin().indices().create(createIndexRequest("test1").alias(new Alias("test"))).actionGet();
client().admin().indices().create(createIndexRequest("test1")
.mapping("type1", "name", "type=keyword,store=true")
.alias(new Alias("test"))).actionGet();
}
@Override

View File

@ -33,6 +33,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import java.io.IOException;
@ -50,7 +51,7 @@ import static org.hamcrest.Matchers.nullValue;
*/
public class DocumentActionsIT extends ESIntegTestCase {
protected void createIndex() {
createIndex(getConcreteIndexName());
ElasticsearchAssertions.assertAcked(prepareCreate(getConcreteIndexName()).addMapping("type1", "name", "type=keyword,store=true"));
}
protected String getConcreteIndexName() {

View File

@ -114,7 +114,9 @@ public class ExplainActionIT extends ESIntegTestCase {
}
public void testExplainWithFields() throws Exception {
assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
assertAcked(prepareCreate("test")
.addMapping("test", "obj1.field1", "type=keyword,store=true", "obj1.field2", "type=keyword,store=true")
.addAlias(new Alias("alias")));
ensureGreen("test");
client().prepareIndex("test", "test", "1")

View File

@ -61,6 +61,7 @@ public class GetActionIT extends ESIntegTestCase {
public void testSimpleGet() {
assertAcked(prepareCreate("test")
.addMapping("type1", "field1", "type=keyword,store=true", "field2", "type=keyword,store=true")
.setSettings(Settings.builder().put("index.refresh_interval", -1))
.addAlias(new Alias("alias")));
ensureGreen();
@ -107,7 +108,7 @@ public class GetActionIT extends ESIntegTestCase {
assertThat(response.getSourceAsMap().get("field1").toString(), equalTo("value1"));
assertThat(response.getSourceAsMap().get("field2").toString(), equalTo("value2"));
logger.info("--> realtime fetch of field (requires fetching parsing source)");
logger.info("--> realtime fetch of field");
response = client().prepareGet(indexOrAlias(), "type1", "1").setFields("field1").get();
assertThat(response.isExists(), equalTo(true));
assertThat(response.getIndex(), equalTo("test"));
@ -115,7 +116,7 @@ public class GetActionIT extends ESIntegTestCase {
assertThat(response.getField("field1").getValues().get(0).toString(), equalTo("value1"));
assertThat(response.getField("field2"), nullValue());
logger.info("--> realtime fetch of field & source (requires fetching parsing source)");
logger.info("--> realtime fetch of field & source");
response = client().prepareGet(indexOrAlias(), "type1", "1").setFields("field1").setFetchSource("field1", null).get();
assertThat(response.isExists(), equalTo(true));
assertThat(response.getIndex(), equalTo("test"));
@ -189,6 +190,7 @@ public class GetActionIT extends ESIntegTestCase {
public void testSimpleMultiGet() throws Exception {
assertAcked(prepareCreate("test").addAlias(new Alias("alias"))
.addMapping("type1", "field", "type=keyword,store=true")
.setSettings(Settings.builder().put("index.refresh_interval", -1)));
ensureGreen();
@ -530,7 +532,7 @@ public class GetActionIT extends ESIntegTestCase {
public void testGetFieldsMetaData() throws Exception {
assertAcked(prepareCreate("test")
.addMapping("parent")
.addMapping("my-type1", "_parent", "type=parent")
.addMapping("my-type1", "_parent", "type=parent", "field1", "type=keyword,store=true")
.addAlias(new Alias("alias"))
.setSettings(Settings.builder().put("index.refresh_interval", -1)));

View File

@ -227,10 +227,10 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
// Check that we can get doc 1 and 2, because we are doing realtime
// gets and getting from the primary
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
flushAndRefresh(IDX);
client().prepareIndex(IDX, "doc", "3").setSource("foo", "bar").get();
@ -238,10 +238,10 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
refresh();
// Check that we can get doc 1 and 2 without realtime
gResp1 = client().prepareGet(IDX, "doc", "1").setRealtime(false).setFields("foo").get();
gResp2 = client().prepareGet(IDX, "doc", "2").setRealtime(false).setFields("foo").get();
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
gResp1 = client().prepareGet(IDX, "doc", "1").setRealtime(false).get();
gResp2 = client().prepareGet(IDX, "doc", "2").setRealtime(false).get();
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
logger.info("--> restarting all nodes");
if (randomBoolean()) {
@ -283,12 +283,12 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
client().prepareIndex(IDX, "doc", "1").setSource("foo", "bar").get();
client().prepareIndex(IDX, "doc", "2").setSource("foo", "bar").get();
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
// Node1 has the primary, now node2 has the replica
String node2 = internalCluster().startNode(nodeSettings);
@ -304,21 +304,21 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).get();
assertHitCount(resp, 2);
gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
gResp1 = client().prepareGet(IDX, "doc", "1").get();
gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.toString(), gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
client().prepareIndex(IDX, "doc", "1").setSource("foo", "foobar").get();
client().prepareIndex(IDX, "doc", "2").setSource("foo", "foobar").get();
gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
gResp1 = client().prepareGet(IDX, "doc", "1").get();
gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.toString(), gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("foobar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("foobar"));
assertThat(gResp1.getSource().get("foo"), equalTo("foobar"));
assertThat(gResp2.getSource().get("foo"), equalTo("foobar"));
}
public void testPrimaryRelocation() throws Exception {
@ -340,12 +340,12 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
client().prepareIndex(IDX, "doc", "1").setSource("foo", "bar").get();
client().prepareIndex(IDX, "doc", "2").setSource("foo", "bar").get();
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
// Node1 has the primary, now node2 has the replica
String node2 = internalCluster().startNode(nodeSettings);
@ -363,21 +363,21 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).get();
assertHitCount(resp, 2);
gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
gResp1 = client().prepareGet(IDX, "doc", "1").get();
gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.toString(), gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
client().prepareIndex(IDX, "doc", "3").setSource("foo", "bar").get();
client().prepareIndex(IDX, "doc", "4").setSource("foo", "bar").get();
gResp1 = client().prepareGet(IDX, "doc", "3").setPreference("_primary").setFields("foo").get();
gResp2 = client().prepareGet(IDX, "doc", "4").setPreference("_primary").setFields("foo").get();
gResp1 = client().prepareGet(IDX, "doc", "3").setPreference("_primary").get();
gResp2 = client().prepareGet(IDX, "doc", "4").setPreference("_primary").get();
assertTrue(gResp1.isExists());
assertTrue(gResp2.isExists());
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
}
public void testPrimaryRelocationWithConcurrentIndexing() throws Exception {
@ -573,10 +573,10 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase {
client().prepareIndex(IDX, "doc", "2").setSource("foo", "bar").get();
flushAndRefresh(IDX);
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").setFields("foo").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").setFields("foo").get();
assertThat(gResp1.getField("foo").getValue().toString(), equalTo("bar"));
assertThat(gResp2.getField("foo").getValue().toString(), equalTo("bar"));
GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertThat(gResp1.getSource().get("foo"), equalTo("bar"));
assertThat(gResp2.getSource().get("foo"), equalTo("bar"));
logger.info("--> performing query");
SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).get();

View File

@ -162,9 +162,4 @@ public class Murmur3FieldMapper extends FieldMapper {
}
}
@Override
public boolean isGenerated() {
return true;
}
}

View File

@ -1,6 +1,20 @@
---
"Fields":
- do:
indices.create:
index: test_1
body:
mappings:
test:
properties:
foo:
type: keyword
store: true
count:
type: integer
store: true
- do:
index:
index: test_1

View File

@ -1,5 +1,17 @@
---
"Source filtering":
- do:
indices.create:
index: test_1
body:
mappings:
test:
properties:
count:
type: integer
store: true
- do:
index:
index: test_1

View File

@ -1,6 +1,20 @@
---
"Fields":
- do:
indices.create:
index: test_1
body:
mappings:
test:
properties:
foo:
type: keyword
store: true
count:
type: integer
store: true
- do:
index:
index: test_1