use of org.opensearch.search.aggregations.support.ValueType in project OpenSearch by opensearch-project.
the class TermsAggregatorTests method testUnmappedWithMissing.
public void testUnmappedWithMissing() throws Exception {
try (Directory directory = newDirectory()) {
try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
Document document = new Document();
document.add(new NumericDocValuesField("unrelated_value", 100));
indexWriter.addDocument(document);
try (IndexReader indexReader = maybeWrapReaderEs(indexWriter.getReader())) {
MappedFieldType fieldType1 = new KeywordFieldMapper.KeywordFieldType("unrelated_value");
IndexSearcher indexSearcher = newIndexSearcher(indexReader);
ValueType[] valueTypes = new ValueType[] { ValueType.STRING, ValueType.LONG, ValueType.DOUBLE };
String[] fieldNames = new String[] { "string", "long", "double" };
Object[] missingValues = new Object[] { "abc", 19L, 19.2 };
for (int i = 0; i < fieldNames.length; i++) {
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name").userValueTypeHint(valueTypes[i]).field(fieldNames[i]).missing(missingValues[i]);
Aggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType1);
aggregator.preCollection();
indexSearcher.search(new MatchAllDocsQuery(), aggregator);
aggregator.postCollection();
Terms result = reduce(aggregator);
assertEquals("_name", result.getName());
assertEquals(1, result.getBuckets().size());
assertEquals(missingValues[i], result.getBuckets().get(0).getKey());
assertEquals(1, result.getBuckets().get(0).getDocCount());
}
}
}
}
}
use of org.opensearch.search.aggregations.support.ValueType in project OpenSearch by opensearch-project.
the class CompositeValuesSourceParserHelper method declareValuesSourceFields.
static <VB extends CompositeValuesSourceBuilder<VB>, T> void declareValuesSourceFields(AbstractObjectParser<VB, T> objectParser) {
objectParser.declareField(VB::field, XContentParser::text, new ParseField("field"), ObjectParser.ValueType.STRING);
objectParser.declareBoolean(VB::missingBucket, new ParseField("missing_bucket"));
objectParser.declareString(VB::missingOrder, new ParseField(MissingOrder.NAME));
objectParser.declareField(VB::userValuetypeHint, p -> {
ValueType valueType = ValueType.lenientParse(p.text());
return valueType;
}, new ParseField("value_type"), ObjectParser.ValueType.STRING);
objectParser.declareField(VB::script, (parser, context) -> Script.parse(parser), Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING);
objectParser.declareField(VB::order, XContentParser::text, new ParseField("order"), ObjectParser.ValueType.STRING);
}
use of org.opensearch.search.aggregations.support.ValueType in project OpenSearch by opensearch-project.
the class TermsAggregatorTests method testUnmapped.
public void testUnmapped() throws Exception {
try (Directory directory = newDirectory()) {
try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
try (IndexReader indexReader = maybeWrapReaderEs(indexWriter.getReader())) {
IndexSearcher indexSearcher = newIndexSearcher(indexReader);
ValueType[] valueTypes = new ValueType[] { ValueType.STRING, ValueType.LONG, ValueType.DOUBLE };
String[] fieldNames = new String[] { "string", "long", "double" };
for (int i = 0; i < fieldNames.length; i++) {
TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder("_name").userValueTypeHint(valueTypes[i]).field(fieldNames[i]);
Aggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, (MappedFieldType) null);
aggregator.preCollection();
indexSearcher.search(new MatchAllDocsQuery(), aggregator);
aggregator.postCollection();
Terms result = reduce(aggregator);
assertEquals("_name", result.getName());
assertEquals(0, result.getBuckets().size());
assertFalse(AggregationInspectionHelper.hasValue((InternalTerms) result));
}
}
}
}
}
use of org.opensearch.search.aggregations.support.ValueType in project OpenSearch by opensearch-project.
the class ValueCountAggregatorTests method testNoDocs.
public void testNoDocs() throws IOException {
for (ValueType valueType : ValueType.values()) {
testAggregation(new MatchAllDocsQuery(), valueType, iw -> {
// Intentionally not writing any docs
}, count -> {
assertEquals(0L, count.getValue());
assertFalse(AggregationInspectionHelper.hasValue(count));
});
}
}
Aggregations