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 #73.

(cherry picked from commit 2e6be20)
This commit is contained in:
David Pilato 2014-07-25 17:53:19 +02:00
parent 1d1225b87c
commit eaccd4383d
5 changed files with 14 additions and 12 deletions

View File

@ -54,7 +54,7 @@ Or it is possible to use more elaborated JSON if content type, resource name or
"_content_type" : "application/pdf",
"_name" : "resource/name/of/my.pdf",
"_language" : "en",
"content" : "... base64 encoded attachment ..."
"_content" : "... base64 encoded attachment ..."
}
}
```
@ -105,13 +105,11 @@ Indexed Characters
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.
Note, this feature is supported since `1.3.0` version.
Metadata parsing error handling
-------------------------------
While extracting metadata content, errors could happen for example when parsing dates.
Since version `1.9.0`, parsing errors are ignored so your document is indexed.
Parsing errors are ignored so your document is indexed.
You can disable this feature by setting the `index.mapping.attachment.ignore_errors` setting to `false`.
@ -128,7 +126,7 @@ Note that you can force language using `_language` field when sending your actua
{
"my_attachment" : {
"_language" : "en",
"content" : "... base64 encoded attachment ..."
"_content" : "... base64 encoded attachment ..."
}
}
```

View File

@ -345,7 +345,11 @@ public class AttachmentMapper implements Mapper {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.VALUE_STRING) {
if ("content".equals(currentFieldName)) {
if ("_content".equals(currentFieldName)) {
content = parser.binaryValue();
} else if ("content".equals(currentFieldName)) {
// TODO Remove in 2.4.0. See #75 https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/75
logger.warn("`content` has been deprecated by _content. Please update your code. Will be removed in a future version.");
content = parser.binaryValue();
} else if ("_content_type".equals(currentFieldName)) {
contentType = parser.text();

View File

@ -71,7 +71,7 @@ public class LanguageDetectionAttachmentMapperTests extends ElasticsearchTestCas
.field("_id", 1)
.startObject("file")
.field("_name", filename)
.field("content", html);
.field("_content", html);
if (forcedLanguage.length > 0) {
xcb.field("_language", forcedLanguage[0]);
@ -128,7 +128,7 @@ public class LanguageDetectionAttachmentMapperTests extends ElasticsearchTestCas
.field("_id", 1)
.startObject("file")
.field("_name", "text-in-english.txt")
.field("content", html)
.field("_content", html)
.field("_detect_language", true)
.endObject().endObject();

View File

@ -57,7 +57,7 @@ public class MetadataMapperTest extends ElasticsearchTestCase {
.field("_id", 1)
.startObject("file")
.field("_name", filename)
.field("content", html)
.field("_content", html)
.endObject()
.endObject().bytes();

View File

@ -90,7 +90,7 @@ public class SimpleAttachmentIntegrationTests extends ElasticsearchIntegrationTe
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
refresh();
CountResponse countResponse = client().prepareCount("test").setQuery(queryString("BeforeLimit").defaultField("file")).execute().get();
@ -108,7 +108,7 @@ public class SimpleAttachmentIntegrationTests extends ElasticsearchIntegrationTe
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
refresh();
CountResponse countResponse = client().prepareCount("test").setQuery(queryString("Begin").defaultField("file")).execute().get();
@ -141,7 +141,7 @@ public class SimpleAttachmentIntegrationTests extends ElasticsearchIntegrationTe
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt)
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt)
.field("_content_type", dummyContentType)
.field("_name", dummyName)
.endObject());