org.elasticsearch.script.CompositeFieldScript Maven / Gradle / Ivy
/*
* 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.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.search.lookup.SearchLookup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A script that emits a map of multiple values, that can then be accessed
* by child runtime fields.
*/
public abstract class CompositeFieldScript extends AbstractFieldScript {
public static final ScriptContext CONTEXT = newContext("composite_field", Factory.class);
@SuppressWarnings("unused")
public static final String[] PARAMETERS = {};
public interface Factory extends ScriptFactory {
CompositeFieldScript.LeafFactory newFactory(String fieldName, Map params, SearchLookup searchLookup);
}
public interface LeafFactory {
CompositeFieldScript newInstance(LeafReaderContext ctx);
}
private final Map> fieldValues = new HashMap<>();
public CompositeFieldScript(String fieldName, Map params, SearchLookup searchLookup, LeafReaderContext ctx) {
super(fieldName, params, searchLookup, ctx);
}
/**
* Runs the object script and returns the values that were emitted for the provided field name
* @param field the field name to extract values from
* @return the values that were emitted for the provided field
*/
public final List