assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));
}
@Test
public void testAnalyzerMappingNotIndexedNorStored() throws Exception {
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("_analyzer").field("path", "field_analyzer").endObject()
.startObject("properties")
.startObject("field_analyzer").field("type", "string").field("index", "no").field("store", "no").endObject()
.startObject("field1").field("type", "string").endObject()
.startObject("field2").field("type", "string").field("analyzer", "simple").endObject()
.endObject()
.endObject().endObject().string();
DocumentMapper documentMapper = parser.parse(mapping);
ParsedDocument doc = documentMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
.field("field1", "value1")
.field("field2", "value2")
.endObject().bytes());
FieldNameAnalyzer analyzer = (FieldNameAnalyzer) doc.analyzer();
assertThat(((NamedAnalyzer) analyzer.defaultAnalyzer()).name(), equalTo("whitespace"));
assertThat(((NamedAnalyzer) analyzer.analyzers().get("field1")), nullValue());
assertThat(((NamedAnalyzer) analyzer.analyzers().get("field2")).name(), equalTo("simple"));
// check that it serializes and de-serializes correctly
DocumentMapper reparsedMapper = parser.parse(documentMapper.mappingSource().string());
doc = reparsedMapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field_analyzer", "whitespace")
.field("field1", "value1")
.field("field2", "value2")