use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.
the class BooleanFieldMapper method parseCreateField.
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) {
return;
}
Boolean value = context.parseExternalValue(Boolean.class);
if (value == null) {
XContentParser.Token token = context.parser().currentToken();
if (token == XContentParser.Token.VALUE_NULL) {
if (fieldType().nullValue() != null) {
value = fieldType().nullValue();
}
} else {
if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
value = context.parser().booleanValue();
} else {
value = context.parser().booleanValueLenient();
if (context.parser().isBooleanValueLenient() != context.parser().isBooleanValue()) {
String rawValue = context.parser().text();
deprecationLogger.deprecated("Expected a boolean for property [{}] but got [{}]", fieldType().name(), rawValue);
}
}
}
}
if (value == null) {
return;
}
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
fields.add(new Field(fieldType().name(), value ? "T" : "F", fieldType()));
}
if (fieldType().hasDocValues()) {
fields.add(new SortedNumericDocValuesField(fieldType().name(), value ? 1 : 0));
}
}
use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.
the class DateFieldMapper method parseCreateField.
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
String dateAsString;
if (context.externalValueSet()) {
Object dateAsObject = context.externalValue();
if (dateAsObject == null) {
dateAsString = null;
} else {
dateAsString = dateAsObject.toString();
}
} else {
dateAsString = context.parser().textOrNull();
}
if (dateAsString == null) {
dateAsString = fieldType().nullValueAsString();
}
if (dateAsString == null) {
return;
}
long timestamp;
try {
timestamp = fieldType().parse(dateAsString);
} catch (IllegalArgumentException e) {
if (ignoreMalformed.value()) {
return;
} else {
throw e;
}
}
if (context.includeInAll(includeInAll, this)) {
context.allEntries().addText(fieldType().name(), dateAsString, fieldType().boost());
}
if (fieldType().indexOptions() != IndexOptions.NONE) {
fields.add(new LongPoint(fieldType().name(), timestamp));
}
if (fieldType().hasDocValues()) {
fields.add(new SortedNumericDocValuesField(fieldType().name(), timestamp));
}
if (fieldType().stored()) {
fields.add(new StoredField(fieldType().name(), timestamp));
}
}
use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.
the class SeqNoFieldMapper method postParse.
@Override
public void postParse(ParseContext context) throws IOException {
// for efficiency.
for (int i = 1; i < context.docs().size(); i++) {
final Document doc = context.docs().get(i);
doc.add(new LongPoint(NAME, 1));
doc.add(new SortedNumericDocValuesField(NAME, 1L));
doc.add(new NumericDocValuesField(PRIMARY_TERM_NAME, 0L));
}
}
use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.
the class StatsAggregatorTests method testRandomDoubles.
public void testRandomDoubles() throws IOException {
MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
ft.setName("field");
final SimpleStatsAggregator expected = new SimpleStatsAggregator();
testCase(ft, iw -> {
int numDocs = randomIntBetween(10, 50);
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
int numValues = randomIntBetween(1, 5);
for (int j = 0; j < numValues; j++) {
double value = randomDoubleBetween(-100d, 100d, true);
long valueAsLong = NumericUtils.doubleToSortableLong(value);
doc.add(new SortedNumericDocValuesField("field", valueAsLong));
expected.add(value);
}
iw.addDocument(doc);
}
}, stats -> {
assertEquals(expected.count, stats.getCount(), 0);
assertEquals(expected.sum, stats.getSum(), TOLERANCE);
assertEquals(expected.min, stats.getMin(), 0);
assertEquals(expected.max, stats.getMax(), 0);
assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
});
}
use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.
the class AvgAggregatorTests method testNoMatchingField.
public void testNoMatchingField() throws IOException {
testCase(new MatchAllDocsQuery(), iw -> {
iw.addDocument(singleton(new SortedNumericDocValuesField("wrong_number", 7)));
iw.addDocument(singleton(new SortedNumericDocValuesField("wrong_number", 3)));
}, avg -> {
assertEquals(Double.NaN, avg.getValue(), 0);
});
}
Aggregations