Skip to content

Commit eaccd43

Browse files
committed
Deprecate content by _content
When we want to force some values, we need to set those using `_field` where `field` is the field name we want to force: ``` { "file": { "_name": "myfilename.txt" } } ``` But to set the content itself, we use `content` field name. ``` { "file": { "content": "VGhpcyBpcyBhbiBlbGFzdGljc2VhcmNoIG1hcHBlciBhdHRhY2htZW50IHRlc3Qu", "_name": "myfilename.txt" } } ``` For consistency, we set `_content` instead: ``` { "file": { "_content": "VGhpcyBpcyBhbiBlbGFzdGljc2VhcmNoIG1hcHBlciBhdHRhY2htZW50IHRlc3Qu", "_name": "myfilename.txt" } } ``` Closes elastic#73. (cherry picked from commit 2e6be20)
1 parent 1d1225b commit eaccd43

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Or it is possible to use more elaborated JSON if content type, resource name or
5454
"_content_type" : "application/pdf",
5555
"_name" : "resource/name/of/my.pdf",
5656
"_language" : "en",
57-
"content" : "... base64 encoded attachment ..."
57+
"_content" : "... base64 encoded attachment ..."
5858
}
5959
}
6060
```
@@ -105,13 +105,11 @@ Indexed Characters
105105

106106
By default, `100000` characters are extracted when indexing the content. This default value can be changed by setting the `index.mapping.attachment.indexed_chars` setting. It can also be provided on a per document indexed using the `_indexed_chars` parameter. `-1` can be set to extract all text, but note that all the text needs to be allowed to be represented in memory.
107107

108-
Note, this feature is supported since `1.3.0` version.
109-
110108
Metadata parsing error handling
111109
-------------------------------
112110

113111
While extracting metadata content, errors could happen for example when parsing dates.
114-
Since version `1.9.0`, parsing errors are ignored so your document is indexed.
112+
Parsing errors are ignored so your document is indexed.
115113

116114
You can disable this feature by setting the `index.mapping.attachment.ignore_errors` setting to `false`.
117115

@@ -128,7 +126,7 @@ Note that you can force language using `_language` field when sending your actua
128126
{
129127
"my_attachment" : {
130128
"_language" : "en",
131-
"content" : "... base64 encoded attachment ..."
129+
"_content" : "... base64 encoded attachment ..."
132130
}
133131
}
134132
```

src/main/java/org/elasticsearch/index/mapper/attachment/AttachmentMapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ public void parse(ParseContext context) throws IOException {
345345
if (token == XContentParser.Token.FIELD_NAME) {
346346
currentFieldName = parser.currentName();
347347
} else if (token == XContentParser.Token.VALUE_STRING) {
348-
if ("content".equals(currentFieldName)) {
348+
if ("_content".equals(currentFieldName)) {
349+
content = parser.binaryValue();
350+
} else if ("content".equals(currentFieldName)) {
351+
// TODO Remove in 2.4.0. See #75 https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/75
352+
logger.warn("`content` has been deprecated by _content. Please update your code. Will be removed in a future version.");
349353
content = parser.binaryValue();
350354
} else if ("_content_type".equals(currentFieldName)) {
351355
contentType = parser.text();

src/test/java/org/elasticsearch/index/mapper/xcontent/LanguageDetectionAttachmentMapperTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void testLanguage(String filename, String expected, String... forcedLang
7171
.field("_id", 1)
7272
.startObject("file")
7373
.field("_name", filename)
74-
.field("content", html);
74+
.field("_content", html);
7575

7676
if (forcedLanguage.length > 0) {
7777
xcb.field("_language", forcedLanguage[0]);
@@ -128,7 +128,7 @@ public void testLangDetectDocumentEnabled() throws Exception {
128128
.field("_id", 1)
129129
.startObject("file")
130130
.field("_name", "text-in-english.txt")
131-
.field("content", html)
131+
.field("_content", html)
132132
.field("_detect_language", true)
133133
.endObject().endObject();
134134

src/test/java/org/elasticsearch/index/mapper/xcontent/MetadataMapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void checkMeta(String filename, Settings settings, Long expectedDate,
5757
.field("_id", 1)
5858
.startObject("file")
5959
.field("_name", filename)
60-
.field("content", html)
60+
.field("_content", html)
6161
.endObject()
6262
.endObject().bytes();
6363

src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testSimpleAttachmentContentLengthLimit() throws Exception {
9090

9191
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
9292

93-
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
93+
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
9494
refresh();
9595

9696
CountResponse countResponse = client().prepareCount("test").setQuery(queryString("BeforeLimit").defaultField("file")).execute().get();
@@ -108,7 +108,7 @@ public void testSimpleAttachmentNoContentLengthLimit() throws Exception {
108108

109109
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
110110

111-
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
111+
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
112112
refresh();
113113

114114
CountResponse countResponse = client().prepareCount("test").setQuery(queryString("Begin").defaultField("file")).execute().get();
@@ -141,7 +141,7 @@ public void testContentTypeAndName() throws Exception {
141141

142142
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
143143

144-
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt)
144+
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt)
145145
.field("_content_type", dummyContentType)
146146
.field("_name", dummyName)
147147
.endObject());

0 commit comments

Comments
 (0)