[Doc] copy_to using attachment field type
If you want to use [copy_to](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to) feature, you need to define it on each sub-field you want to copy to another field: ```javascript PUT /test/person/_mapping { "person": { "properties": { "file": { "type": "attachment", "path": "full", "fields": { "file": { "type": "string", "copy_to": "copy" } } }, "copy": { "type": "string" } } } } ``` In this example, the extracted content will be copy as well to `copy` field. Closes #97. (cherry picked from commit f4f6b57) (cherry picked from commit 5878a62)
This commit is contained in:
parent
ec59d381b8
commit
77081e3dbf
31
README.md
31
README.md
|
@ -117,6 +117,37 @@ In the above example, the actual content indexed is mapped under `fields` name `
|
||||||
it will only be available in the `_all` field. The other fields map to their respective metadata names, but there is no
|
it will only be available in the `_all` field. The other fields map to their respective metadata names, but there is no
|
||||||
need to specify the `type` (like `string` or `date`) since it is already known.
|
need to specify the `type` (like `string` or `date`) since it is already known.
|
||||||
|
|
||||||
|
Copy To feature
|
||||||
|
---------------
|
||||||
|
|
||||||
|
If you want to use [copy_to](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)
|
||||||
|
feature, you need to define it on each sub-field you want to copy to another field:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
PUT /test/person/_mapping
|
||||||
|
{
|
||||||
|
"person": {
|
||||||
|
"properties": {
|
||||||
|
"file": {
|
||||||
|
"type": "attachment",
|
||||||
|
"path": "full",
|
||||||
|
"fields": {
|
||||||
|
"file": {
|
||||||
|
"type": "string",
|
||||||
|
"copy_to": "copy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"copy": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, the extracted content will be copy as well to `copy` field.
|
||||||
|
|
||||||
Querying or accessing metadata
|
Querying or accessing metadata
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.index.mapper.MapperParsingException;
|
||||||
import org.elasticsearch.plugins.PluginsService;
|
import org.elasticsearch.plugins.PluginsService;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.client.Requests.putMappingRequest;
|
import static org.elasticsearch.client.Requests.putMappingRequest;
|
||||||
|
@ -149,4 +150,42 @@ public class SimpleAttachmentIntegrationTests extends ElasticsearchIntegrationTe
|
||||||
assertThat(name, is(dummyName));
|
assertThat(name, is(dummyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As for now, we don't support a global `copy_to` property for `attachment` type.
|
||||||
|
* So this test is failing.
|
||||||
|
*/
|
||||||
|
@Test @Ignore
|
||||||
|
public void testCopyTo() throws Exception {
|
||||||
|
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/copy-to/copy-to.json");
|
||||||
|
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/text-in-english.txt");
|
||||||
|
|
||||||
|
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||||
|
|
||||||
|
index("test", "person", jsonBuilder().startObject().field("file", txt).endObject());
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
CountResponse countResponse = client().prepareCount("test").setQuery(queryStringQuery("Queen").defaultField("file")).execute().get();
|
||||||
|
assertThat(countResponse.getCount(), equalTo(1l));
|
||||||
|
|
||||||
|
countResponse = client().prepareCount("test").setQuery(queryStringQuery("Queen").defaultField("copy")).execute().get();
|
||||||
|
assertThat(countResponse.getCount(), equalTo(1l));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopyToSubField() throws Exception {
|
||||||
|
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/copy-to/copy-to-subfield.json");
|
||||||
|
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/text-in-english.txt");
|
||||||
|
|
||||||
|
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||||
|
|
||||||
|
index("test", "person", jsonBuilder().startObject().field("file", txt).endObject());
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
CountResponse countResponse = client().prepareCount("test").setQuery(queryStringQuery("Queen").defaultField("file")).execute().get();
|
||||||
|
assertThat(countResponse.getCount(), equalTo(1l));
|
||||||
|
|
||||||
|
countResponse = client().prepareCount("test").setQuery(queryStringQuery("Queen").defaultField("copy")).execute().get();
|
||||||
|
assertThat(countResponse.getCount(), equalTo(1l));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"person": {
|
||||||
|
"properties": {
|
||||||
|
"file": {
|
||||||
|
"type": "attachment",
|
||||||
|
"path": "full",
|
||||||
|
"fields": {
|
||||||
|
"file": {
|
||||||
|
"type": "string",
|
||||||
|
"copy_to": "copy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"copy": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"person": {
|
||||||
|
"properties": {
|
||||||
|
"file": {
|
||||||
|
"type": "attachment",
|
||||||
|
"copy_to": "copy"
|
||||||
|
},
|
||||||
|
"copy": {
|
||||||
|
"type": "attachment"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue