org.elasticsearch.index.fielddata.IndexNumericFieldData Java Examples
The following examples show how to use
org.elasticsearch.index.fielddata.IndexNumericFieldData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BytesRefTermStream.java From siren-join with GNU Affero General Public License v3.0 | 6 votes |
/** * Instantiates a new reusable {@link BytesRefTermStream} based on the field type. */ public static BytesRefTermStream get(IndexReader reader, IndexFieldData indexFieldData) { if (indexFieldData instanceof IndexNumericFieldData) { IndexNumericFieldData numFieldData = (IndexNumericFieldData) indexFieldData; switch (numFieldData.getNumericType()) { case INT: return new IntegerBytesRefTermStream(reader, numFieldData); case LONG: return new LongBytesRefTermStream(reader, numFieldData); default: throw new UnsupportedOperationException("Streaming numeric type '" + numFieldData.getNumericType().name() + "' is unsupported"); } } else { return new BytesBytesRefTermStream(reader, indexFieldData); } }
Example #2
Source File: DecayFunctionParser.java From Elasticsearch with Apache License 2.0 | 5 votes |
private AbstractDistanceScoreFunction parseNumberVariable(String fieldName, XContentParser parser, QueryParseContext parseContext, NumberFieldMapper.NumberFieldType fieldType, MultiValueMode mode) throws IOException { XContentParser.Token token; String parameterName = null; double scale = 0; double origin = 0; double decay = 0.5; double offset = 0.0d; boolean scaleFound = false; boolean refFound = false; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { parameterName = parser.currentName(); } else if (parameterName.equals(DecayFunctionBuilder.SCALE)) { scale = parser.doubleValue(); scaleFound = true; } else if (parameterName.equals(DecayFunctionBuilder.DECAY)) { decay = parser.doubleValue(); } else if (parameterName.equals(DecayFunctionBuilder.ORIGIN)) { origin = parser.doubleValue(); refFound = true; } else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) { offset = parser.doubleValue(); } else { throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName); } } if (!scaleFound || !refFound) { throw new ElasticsearchParseException("both [{}] and [{}] must be set for numeric fields.", DecayFunctionBuilder.SCALE, DecayFunctionBuilder.ORIGIN); } IndexNumericFieldData numericFieldData = parseContext.getForField(fieldType); return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode); }
Example #3
Source File: DecayFunctionParser.java From Elasticsearch with Apache License 2.0 | 5 votes |
private AbstractDistanceScoreFunction parseDateVariable(String fieldName, XContentParser parser, QueryParseContext parseContext, DateFieldMapper.DateFieldType dateFieldType, MultiValueMode mode) throws IOException { XContentParser.Token token; String parameterName = null; String scaleString = null; String originString = null; String offsetString = "0d"; double decay = 0.5; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { parameterName = parser.currentName(); } else if (parameterName.equals(DecayFunctionBuilder.SCALE)) { scaleString = parser.text(); } else if (parameterName.equals(DecayFunctionBuilder.ORIGIN)) { originString = parser.text(); } else if (parameterName.equals(DecayFunctionBuilder.DECAY)) { decay = parser.doubleValue(); } else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) { offsetString = parser.text(); } else { throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName); } } long origin = SearchContext.current().nowInMillis(); if (originString != null) { origin = dateFieldType.parseToMilliseconds(originString, false, null, null); } if (scaleString == null) { throw new ElasticsearchParseException("[{}] must be set for date fields.", DecayFunctionBuilder.SCALE); } TimeValue val = TimeValue.parseTimeValue(scaleString, TimeValue.timeValueHours(24), getClass().getSimpleName() + ".scale"); double scale = val.getMillis(); val = TimeValue.parseTimeValue(offsetString, TimeValue.timeValueHours(24), getClass().getSimpleName() + ".offset"); double offset = val.getMillis(); IndexNumericFieldData numericFieldData = parseContext.getForField(dateFieldType); return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode); }
Example #4
Source File: NumericTermStream.java From siren-join with GNU Affero General Public License v3.0 | 5 votes |
/** * Instantiates a new reusable {@link NumericTermStream} based on the field type. */ public static NumericTermStream get(IndexReader reader, IndexFieldData indexFieldData) { if (indexFieldData instanceof IndexNumericFieldData) { IndexNumericFieldData numFieldData = (IndexNumericFieldData) indexFieldData; if (!numFieldData.getNumericType().isFloatingPoint()) { return new LongTermStream(reader, numFieldData); } else { throw new UnsupportedOperationException("Streaming floating points is unsupported"); } } else { return new HashTermStream(reader, indexFieldData); } }
Example #5
Source File: BytesRefTermStream.java From siren-join with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void set(int atomicReaderId, int atomicDocId) { // loading values from field data cache is costly, // therefore we load values from cache only if new atomic reader id if (lastAtomicReaderId != atomicReaderId) { LeafReaderContext leafReader = reader.leaves().get(atomicReaderId); this.values = ((IndexNumericFieldData) this.fieldData).load(leafReader).getLongValues(); } this.values.setDocument(atomicDocId); this.count = 0; this.lastAtomicReaderId = atomicReaderId; }
Example #6
Source File: FieldDataTermsQueryParser.java From siren-join with GNU Affero General Public License v3.0 | 5 votes |
private final Query toFieldDataTermsQuery(MappedFieldType fieldType, IndexFieldData fieldData, byte[] encodedTerms, long cacheKey) { Query query = null; if (fieldType instanceof NumberFieldMapper.NumberFieldType) { query = FieldDataTermsQuery.newLongs(encodedTerms, (IndexNumericFieldData) fieldData, cacheKey); } else if (fieldType instanceof StringFieldMapper.StringFieldType) { query = FieldDataTermsQuery.newBytes(encodedTerms, fieldData, cacheKey); } else { throw new ElasticsearchParseException("[fielddata_terms] query does not support field data type " + fieldType.fieldDataType().getType()); } return query; }
Example #7
Source File: AggregationContext.java From Elasticsearch with Apache License 2.0 | 5 votes |
private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException { if (!(config.fieldContext.indexFieldData() instanceof IndexNumericFieldData)) { throw new IllegalArgumentException("Expected numeric type on field [" + config.fieldContext.field() + "], but got [" + config.fieldContext.fieldType().typeName() + "]"); } ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData()); if (config.script != null) { dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script); } return dataSource; }
Example #8
Source File: FieldValueFactorFunction.java From Elasticsearch with Apache License 2.0 | 5 votes |
public FieldValueFactorFunction(String field, float boostFactor, Modifier modifierType, Double missing, IndexNumericFieldData indexFieldData) { super(CombineFunction.MULT); this.field = field; this.boostFactor = boostFactor; this.modifier = modifierType; this.indexFieldData = indexFieldData; this.missing = missing; }
Example #9
Source File: FieldDataTermsQuery.java From siren-join with GNU Affero General Public License v3.0 | 5 votes |
@Override public DocIdSet getDocIdSet(LeafReaderContext context) throws IOException { final NumericTermsSet termsSet = this.getTermsSet(); // make sure there are terms to filter on if (termsSet == null || termsSet.isEmpty()) return null; IndexNumericFieldData numericFieldData = (IndexNumericFieldData) fieldData; if (!numericFieldData.getNumericType().isFloatingPoint()) { final SortedNumericDocValues values = numericFieldData.load(context).getLongValues(); // load fielddata return new DocValuesDocIdSet(context.reader().maxDoc(), context.reader().getLiveDocs()) { @Override protected boolean matchDoc(int doc) { values.setDocument(doc); final int numVals = values.count(); for (int i = 0; i < numVals; i++) { if (termsSet.contains(values.valueAt(i))) { return true; } } return false; } }; } // only get here if wrong fielddata type in which case // no docs will match so we just return null. return null; }
Example #10
Source File: DoubleValuesComparatorSource.java From Elasticsearch with Apache License 2.0 | 4 votes |
public DoubleValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue, MultiValueMode sortMode, Nested nested) { this.indexFieldData = indexFieldData; this.missingValue = missingValue; this.sortMode = sortMode; this.nested = nested; }
Example #11
Source File: NumericTermStream.java From siren-join with GNU Affero General Public License v3.0 | 4 votes |
protected LongTermStream(IndexReader reader, IndexNumericFieldData fieldData) { super(reader); this.fieldData = fieldData; }
Example #12
Source File: FloatValuesComparatorSource.java From Elasticsearch with Apache License 2.0 | 4 votes |
public FloatValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue, MultiValueMode sortMode, Nested nested) { this.indexFieldData = indexFieldData; this.missingValue = missingValue; this.sortMode = sortMode; this.nested = nested; }
Example #13
Source File: LongValuesComparatorSource.java From Elasticsearch with Apache License 2.0 | 4 votes |
public LongValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue, MultiValueMode sortMode, Nested nested) { this.indexFieldData = indexFieldData; this.missingValue = missingValue; this.sortMode = sortMode; this.nested = nested; }
Example #14
Source File: FieldValueFactorFunctionParser.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException { String currentFieldName = null; String field = null; float boostFactor = 1; FieldValueFactorFunction.Modifier modifier = FieldValueFactorFunction.Modifier.NONE; Double missing = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if ("field".equals(currentFieldName)) { field = parser.text(); } else if ("factor".equals(currentFieldName)) { boostFactor = parser.floatValue(); } else if ("modifier".equals(currentFieldName)) { modifier = FieldValueFactorFunction.Modifier.valueOf(parser.text().toUpperCase(Locale.ROOT)); } else if ("missing".equals(currentFieldName)) { missing = parser.doubleValue(); } else { throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]"); } } else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) { throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] field 'factor' does not support lists or objects"); } } if (field == null) { throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] required field 'field' missing"); } SearchContext searchContext = SearchContext.current(); MappedFieldType fieldType = searchContext.mapperService().smartNameFieldType(field); IndexNumericFieldData fieldData = null; if (fieldType == null) { if(missing == null) { throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined."); } } else { fieldData = searchContext.fieldData().getForField(fieldType); } return new FieldValueFactorFunction(field, boostFactor, modifier, missing, fieldData); }
Example #15
Source File: DecayFunctionParser.java From Elasticsearch with Apache License 2.0 | 4 votes |
public NumericFieldDataScoreFunction(double origin, double scale, double decay, double offset, DecayFunction func, IndexNumericFieldData fieldData, MultiValueMode mode) { super(scale, decay, offset, func, mode); this.fieldData = fieldData; this.origin = origin; }
Example #16
Source File: ValuesSource.java From Elasticsearch with Apache License 2.0 | 4 votes |
public FieldData(IndexNumericFieldData indexFieldData) { this.indexFieldData = indexFieldData; }
Example #17
Source File: FieldDataTermsQuery.java From siren-join with GNU Affero General Public License v3.0 | 2 votes |
/** * Get a {@link FieldDataTermsQuery} that filters on non-floating point numeric terms found in a hppc * {@link LongHashSet}. * * @param encodedTerms An encoded set of terms. * @param fieldData The fielddata for the field. * @param cacheKey A unique key to use for caching this query. * @return the query. */ public static FieldDataTermsQuery newLongs(final byte[] encodedTerms, final IndexNumericFieldData fieldData, final long cacheKey) { return new LongsFieldDataTermsQuery(encodedTerms, fieldData, cacheKey); }