use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class BooleanFieldMapperTests method setup.
@Before
public void setup() {
indexService = createIndex("test");
parser = indexService.mapperService().documentMapperParser();
IndexService preEs6IndexService = createIndex("legacy", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_0_0).build());
preEs6Parser = preEs6IndexService.mapperService().documentMapperParser();
}
use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class DoubleIndexingDocTests method testDoubleIndexingSameDoc.
public void testDoubleIndexingSameDoc() throws Exception {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random(), Lucene.STANDARD_ANALYZER));
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").endObject().endObject().endObject().string();
IndexService index = createIndex("test");
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get();
DocumentMapper mapper = index.mapperService().documentMapper("type");
QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L);
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field1", "value1").field("field2", 1).field("field3", 1.1).field("field4", "2010-01-01").startArray("field5").value(1).value(2).value(3).endArray().endObject().bytes());
assertNotNull(doc.dynamicMappingsUpdate());
client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
mapper = index.mapperService().documentMapper("type");
writer.addDocument(doc.rootDoc());
writer.addDocument(doc.rootDoc());
IndexReader reader = DirectoryReader.open(writer);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field1").fieldType().termQuery("value1", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field2").fieldType().termQuery("1", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field3").fieldType().termQuery("1.1", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field4").fieldType().termQuery("2010-01-01", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("1", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("2", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("3", context), 10);
assertThat(topDocs.totalHits, equalTo(2));
writer.close();
reader.close();
dir.close();
}
use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testEmptyName.
public void testEmptyName() throws IOException {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("").field("type", "completion").endObject().endObject().endObject().endObject().string();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
assertThat(e.getMessage(), containsString("name cannot be empty string"));
}
use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class DocumentMapperParserTests method testFieldNameWithDots.
public void testFieldNameWithDots() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo.bar").field("type", "text").endObject().startObject("foo.baz").field("type", "keyword").endObject().endObject().endObject().endObject().string();
DocumentMapper docMapper = mapperParser.parse("type", new CompressedXContent(mapping));
assertNotNull(docMapper.mappers().getMapper("foo.bar"));
assertNotNull(docMapper.mappers().getMapper("foo.baz"));
assertNotNull(docMapper.objectMappers().get("foo"));
}
use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class CopyToMapperTests method testCopyToNestedField.
public void testCopyToNestedField() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
XContentBuilder mapping = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("target").field("type", "long").field("doc_values", false).endObject().startObject("n1").field("type", "nested").startObject("properties").startObject("target").field("type", "long").field("doc_values", false).endObject().startObject("n2").field("type", "nested").startObject("properties").startObject("target").field("type", "long").field("doc_values", false).endObject().startObject("source").field("type", "long").field("doc_values", false).startArray("copy_to").value(// should go to the root doc
"target").value(// should go to the parent doc
"n1.target").value(// should go to the current doc
"n1.n2.target").endArray().endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject();
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping.string()));
XContentBuilder jsonDoc = XContentFactory.jsonBuilder().startObject().startArray("n1").startObject().startArray("n2").startObject().field("source", 3).endObject().startObject().field("source", 5).endObject().endArray().endObject().startObject().startArray("n2").startObject().field("source", 7).endObject().endArray().endObject().endArray().endObject();
ParsedDocument doc = mapper.parse("test", "type", "1", jsonDoc.bytes());
assertEquals(6, doc.docs().size());
Document nested = doc.docs().get(0);
assertFieldValue(nested, "n1.n2.target", 7L);
assertFieldValue(nested, "n1.target");
assertFieldValue(nested, "target");
nested = doc.docs().get(2);
assertFieldValue(nested, "n1.n2.target", 5L);
assertFieldValue(nested, "n1.target");
assertFieldValue(nested, "target");
nested = doc.docs().get(3);
assertFieldValue(nested, "n1.n2.target", 3L);
assertFieldValue(nested, "n1.target");
assertFieldValue(nested, "target");
Document parent = doc.docs().get(1);
assertFieldValue(parent, "target");
assertFieldValue(parent, "n1.target", 7L);
assertFieldValue(parent, "n1.n2.target");
parent = doc.docs().get(4);
assertFieldValue(parent, "target");
assertFieldValue(parent, "n1.target", 3L, 5L);
assertFieldValue(parent, "n1.n2.target");
Document root = doc.docs().get(5);
assertFieldValue(root, "target", 3L, 5L, 7L);
assertFieldValue(root, "n1.target");
assertFieldValue(root, "n1.n2.target");
}
Aggregations