All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.o19s.es.ltr.utils.AbstractQueryBuilderUtils Maven / Gradle / Ivy

There is a newer version: 6.8.0
Show newest version
package com.o19s.es.ltr.utils;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.AbstractObjectParser;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AbstractQueryBuilderUtils {

    /**
     * Method copied from the {@link org.elasticsearch.index.query.AbstractQueryBuilder}. Scope was reduced to
     * package private. But we use it in multiple subclasses.
     *
     * An issue is send to elastic to ask for a change to make it available again:
     * https://github.com/elastic/elasticsearch/issues/27865
     *
     * @param parser Instance of a parser declare some default values for fields
     */
    public static void declareStandardFields(AbstractObjectParser parser) {
        parser.declareFloat(QueryBuilder::boost, AbstractQueryBuilder.BOOST_FIELD);
        parser.declareString(QueryBuilder::queryName, AbstractQueryBuilder.NAME_FIELD);
    }

    public static void writeQueries(StreamOutput out, List queries) throws IOException {
        out.writeVInt(queries.size());
        for (QueryBuilder query : queries) {
            out.writeNamedWriteable(query);
        }
    }

    public static List readQueries(StreamInput in) throws IOException {
        int size = in.readVInt();
        List queries = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            queries.add(in.readNamedWriteable(QueryBuilder.class));
        }
        return queries;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy