org.elasticsearch.script.DocBasedScript Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.script;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.script.field.EmptyField;
import org.elasticsearch.script.field.Field;
import org.elasticsearch.search.lookup.Source;
import org.elasticsearch.xcontent.XContentType;
import java.util.Collections;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;
public abstract class DocBasedScript {
protected final DocReader docReader;
public DocBasedScript(DocReader docReader) {
this.docReader = docReader;
}
public Field> field(String fieldName) {
if (docReader == null) {
return new EmptyField(fieldName);
}
return docReader.field(fieldName);
}
public Stream> fields(String fieldGlob) {
if (docReader == null) {
return Stream.empty();
}
return docReader.fields(fieldGlob);
}
/**
* Set the current document to run the script on next.
*/
public void setDocument(int docID) {
if (docReader != null) {
docReader.setDocument(docID);
}
}
public Map docAsMap() {
if (docReader == null) {
return Collections.emptyMap();
}
return docReader.docAsMap();
}
public Supplier