use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class DateFieldMapperTests method testTimeZoneParsing.
/**
* Test that time zones are correctly parsed by the {@link DateFieldMapper}.
* There is a known bug with Joda 2.9.4 reported in https://github.com/JodaOrg/joda-time/issues/373.
*/
public void testTimeZoneParsing() throws Exception {
final String timeZonePattern = "yyyy-MM-dd" + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'");
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "date").field("format", timeZonePattern).endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone();
final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone);
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate)).endObject().bytes());
IndexableField[] fields = doc.rootDoc().getFields("field");
assertEquals(2, fields.length);
assertEquals(randomDate.withZone(DateTimeZone.UTC).getMillis(), fields[0].numericValue().longValue());
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testParsingMultiValued.
public void testParsingMultiValued() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
MappedFieldType completionFieldType = fieldMapper.fieldType();
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder().startObject().array("completion", "suggestion1", "suggestion2").endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertSuggestFields(fields, 2);
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class HalfFloatFielddataTests method testSingleValued.
public void testSingleValued() throws IOException {
Directory dir = newDirectory();
// we need the default codec to check for singletons
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null).setCodec(TestUtil.getDefaultCodec()));
Document doc = new Document();
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false)) {
doc.add(f);
}
w.addDocument(doc);
final DirectoryReader dirReader = DirectoryReader.open(w);
LeafReader reader = getOnlyLeafReader(dirReader);
SortedNumericDoubleValues values = new SortedNumericDVIndexFieldData.SortedNumericHalfFloatFieldData(reader, "half_float").getDoubleValues();
assertNotNull(FieldData.unwrapSingleton(values));
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(3f, values.valueAt(0), 0f);
IOUtils.close(dirReader, w, dir);
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testParsingFull.
public void testParsingFull() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
MappedFieldType completionFieldType = fieldMapper.fieldType();
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder().startObject().startArray("completion").startObject().field("input", "suggestion1").field("weight", 3).endObject().startObject().field("input", "suggestion2").field("weight", 4).endObject().startObject().field("input", "suggestion3").field("weight", 5).endObject().endArray().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertSuggestFields(fields, 3);
}
use of org.apache.lucene.index.IndexableField in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testParsingWithWeight.
public void testParsingWithWeight() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
MappedFieldType completionFieldType = fieldMapper.fieldType();
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder().startObject().startObject("completion").field("input", "suggestion").field("weight", 2).endObject().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertSuggestFields(fields, 1);
}
Aggregations