Skip to content

Commit 4597111

Browse files
committed
Remove support for stored fields.
1 parent 7a750d1 commit 4597111

File tree

4 files changed

+13
-136
lines changed

4 files changed

+13
-136
lines changed

docs/reference/mapping/types/embedded-json.asciidoc

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,8 @@ keyword-style aggregations such as `terms`. As with queries, there is no
113113
special support for numerics -- all values in the JSON object are treated as
114114
keywords. When sorting, this implies that values are compared lexicographically.
115115

116-
[[stored-fields]]
117-
==== Stored fields
118-
119-
If the <<mapping-store,`store`>> option is enabled, the entire JSON object will
120-
be stored in pretty-printed format. It can be retrieved through the top-level
121-
`embedded_json` field:
122-
123-
[source,js]
124-
--------------------------------
125-
POST bug_reports/_search
126-
{
127-
"query": { "match": { "title": "results not sorted" }},
128-
"stored_fields": ["labels"]
129-
}
130-
--------------------------------
131-
// CONSOLE
132-
133-
Field keys cannot be used to load stored content. For example, specifying
134-
`"stored_fields": ["labels.timestamp"]` will return an empty list.
116+
Embedded JSON fields currently cannot be stored. It is not possible to specify
117+
the <<mapping-store, `store`>> parameter in the mapping.
135118

136119
[[json-params]]
137120
==== Parameters for JSON fields

server/src/main/java/org/elasticsearch/index/mapper/JsonFieldMapper.java

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.index.mapper;
2121

2222
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
23-
import org.apache.lucene.document.StoredField;
2423
import org.apache.lucene.index.DirectoryReader;
2524
import org.apache.lucene.index.IndexOptions;
2625
import org.apache.lucene.index.IndexableField;
@@ -34,14 +33,11 @@
3433
import org.apache.lucene.search.SortField;
3534
import org.apache.lucene.search.TermQuery;
3635
import org.apache.lucene.util.BytesRef;
37-
import org.elasticsearch.common.bytes.BytesReference;
3836
import org.elasticsearch.common.lucene.Lucene;
3937
import org.elasticsearch.common.settings.Settings;
4038
import org.elasticsearch.common.unit.Fuzziness;
4139
import org.elasticsearch.common.xcontent.XContentBuilder;
42-
import org.elasticsearch.common.xcontent.XContentFactory;
4340
import org.elasticsearch.common.xcontent.XContentParser;
44-
import org.elasticsearch.common.xcontent.json.JsonXContent;
4541
import org.elasticsearch.common.xcontent.support.XContentMapValues;
4642
import org.elasticsearch.index.Index;
4743
import org.elasticsearch.index.IndexSettings;
@@ -90,9 +86,6 @@
9086
* the mapper will produce untokenized string fields called "json_field" with values "some value" and "true",
9187
* as well as string fields called "json_field._keyed" with values "key\0some value" and "key2.key3\0true".
9288
* Note that \0 is used as a reserved separator character (see {@link JsonFieldParser#SEPARATOR}).
93-
*
94-
* When 'store' is enabled, a single stored field is added containing the entire JSON object in
95-
* pretty-printed format.
9689
*/
9790
public final class JsonFieldMapper extends FieldMapper {
9891

@@ -175,6 +168,11 @@ public Builder copyTo(CopyTo copyTo) {
175168
throw new UnsupportedOperationException("[copy_to] is not supported for [" + CONTENT_TYPE + "] fields.");
176169
}
177170

171+
@Override
172+
public Builder store(boolean store) {
173+
throw new UnsupportedOperationException("[store] is not supported for [" + CONTENT_TYPE + "] fields.");
174+
}
175+
178176
@Override
179177
public JsonFieldMapper build(BuilderContext context) {
180178
setupFieldType(context);
@@ -579,34 +577,13 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
579577
return;
580578
}
581579

582-
if (fieldType.indexOptions() == IndexOptions.NONE
583-
&& !fieldType.hasDocValues()
584-
&& !fieldType.stored()) {
580+
if (fieldType.indexOptions() == IndexOptions.NONE && !fieldType.hasDocValues()) {
585581
context.parser().skipChildren();
586582
return;
587583
}
588584

589-
BytesRef storedValue = null;
590-
if (fieldType.stored()) {
591-
XContentBuilder builder = XContentFactory.jsonBuilder()
592-
.prettyPrint()
593-
.copyCurrentStructure(context.parser());
594-
storedValue = BytesReference.bytes(builder).toBytesRef();
595-
fields.add(new StoredField(fieldType.name(), storedValue));
596-
}
597-
598-
XContentParser indexedFieldsParser = context.parser();
599-
600-
// If store is enabled, we've already consumed the content to produce the stored field. Here we
601-
// 'reset' the parser, so that we can traverse the content again.
602-
if (storedValue != null) {
603-
indexedFieldsParser = JsonXContent.jsonXContent.createParser(context.parser().getXContentRegistry(),
604-
context.parser().getDeprecationHandler(),
605-
storedValue.bytes);
606-
indexedFieldsParser.nextToken();
607-
}
608-
609-
fields.addAll(fieldParser.parse(indexedFieldsParser));
585+
XContentParser xContentParser = context.parser();
586+
fields.addAll(fieldParser.parse(xContentParser));
610587

611588
if (!fieldType.hasDocValues()) {
612589
createFieldNamesField(context, fields);

server/src/test/java/org/elasticsearch/index/mapper/JsonFieldMapperTests.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -186,54 +186,16 @@ public void testEnableStore() throws Exception {
186186
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
187187
.startObject("type")
188188
.startObject("properties")
189-
.startObject("store")
190-
.field("type", "embedded_json")
191-
.field("store", true)
192-
.endObject()
193-
.startObject("store_only")
189+
.startObject("field")
194190
.field("type", "embedded_json")
195-
.field("index", false)
196191
.field("store", true)
197-
.field("doc_values", false)
198192
.endObject()
199193
.endObject()
200194
.endObject()
201195
.endObject());
202196

203-
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
204-
assertEquals(mapping, mapper.mappingSource().toString());
205-
206-
BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject()
207-
.startObject("store")
208-
.field("key", "value")
209-
.endObject()
210-
.startObject("store_only")
211-
.field("key", "value")
212-
.endObject()
213-
.endObject());
214-
ParsedDocument parsedDoc = mapper.parse(new SourceToParse("test", "type", "1", doc, XContentType.JSON));
215-
216-
// We make sure to pretty-print here, since the field is always stored in pretty-printed format.
217-
BytesReference storedValue = BytesReference.bytes(JsonXContent.contentBuilder()
218-
.prettyPrint()
219-
.startObject()
220-
.field("key", "value")
221-
.endObject());
222-
223-
IndexableField[] store = parsedDoc.rootDoc().getFields("store");
224-
assertEquals(3, store.length);
225-
226-
assertTrue(store[0].fieldType().stored());
227-
assertEquals(storedValue.toBytesRef(), store[0].binaryValue());
228-
assertFalse(store[1].fieldType().stored());
229-
assertFalse(store[2].fieldType().stored());
230-
assertEquals(DocValuesType.SORTED_SET, store[2].fieldType().docValuesType());
231-
232-
IndexableField[] storeOnly = parsedDoc.rootDoc().getFields("store_only");
233-
assertEquals(1, storeOnly.length);
234-
235-
assertTrue(storeOnly[0].fieldType().stored());
236-
assertEquals(storedValue.toBytesRef(), storeOnly[0].binaryValue());
197+
expectThrows(UnsupportedOperationException.class, () ->
198+
parser.parse("type", new CompressedXContent(mapping)));
237199
}
238200

239201
public void testIndexOptions() throws IOException {

server/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,51 +1227,6 @@ public void testLoadMetadata() throws Exception {
12271227
assertThat(fields.get("_routing").getValue().toString(), equalTo("1"));
12281228
}
12291229

1230-
public void testJsonStoredFields() throws Exception {
1231-
XContentBuilder mapping = XContentFactory.jsonBuilder()
1232-
.startObject()
1233-
.startObject("_doc")
1234-
.startObject("properties")
1235-
.startObject("json_field")
1236-
.field("type", "embedded_json")
1237-
.field("store", true)
1238-
.endObject()
1239-
.endObject()
1240-
.endObject()
1241-
.endObject();
1242-
assertAcked(prepareCreate("test").addMapping("_doc", mapping));
1243-
ensureGreen("test");
1244-
1245-
XContentBuilder source = XContentFactory.jsonBuilder()
1246-
.startObject()
1247-
.startObject("json_field")
1248-
.field("key", "value")
1249-
.endObject()
1250-
.endObject();
1251-
index("test", "_doc", "1", source);
1252-
refresh("test");
1253-
1254-
SearchResponse response = client().prepareSearch("test")
1255-
.addStoredField("json_field")
1256-
.addStoredField("json_field.key")
1257-
.get();
1258-
assertSearchResponse(response);
1259-
assertHitCount(response, 1);
1260-
1261-
Map<String, DocumentField> fields = response.getHits().getAt(0).getFields();
1262-
DocumentField field = fields.get("json_field");
1263-
assertEquals("json_field", field.getName());
1264-
assertFalse(fields.containsKey("json_field.key"));
1265-
1266-
// We make sure to pretty-print here, since the field is always stored in pretty-printed format.
1267-
BytesReference storedValue = BytesReference.bytes(XContentFactory.jsonBuilder()
1268-
.prettyPrint()
1269-
.startObject()
1270-
.field("key", "value")
1271-
.endObject());
1272-
assertEquals(storedValue.utf8ToString(), field.getValue());
1273-
}
1274-
12751230
public void testJsonDocValuesFields() throws Exception {
12761231
XContentBuilder mapping = XContentFactory.jsonBuilder()
12771232
.startObject()

0 commit comments

Comments
 (0)