io.polyglotted.eswrapper.query.ResultBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es-wrapper Show documentation
Show all versions of es-wrapper Show documentation
Standard set of utilities for elastic search abstraction
package io.polyglotted.eswrapper.query;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import io.polyglotted.pgmodel.search.IndexKey;
import io.polyglotted.pgmodel.search.SimpleDoc;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.ImmutableMap.copyOf;
import static com.google.common.collect.ImmutableMap.of;
import static com.google.common.collect.Iterables.transform;
import static io.polyglotted.eswrapper.query.ModelQueryUtil.keyFrom;
public interface ResultBuilder {
default List buildFrom(SearchResponse response) {
return ImmutableList.copyOf(transform(response.getHits(), hit -> {
ImmutableMap source = hit.isSourceEmpty() ? of() : copyOf(hit.getSource());
return buildResult(keyFrom(hit), source);
}));
}
default T buildFrom(GetResponse response) {
ImmutableMap source = response.isSourceEmpty() ? of() : copyOf(response.getSourceAsMap());
return buildResult(keyFrom(response), source);
}
T buildResult(IndexKey key, ImmutableMap source);
ResultBuilder> NullBuilder = (key, source) -> ImmutableMap.of();
ResultBuilder IndexKeyBuilder = (key, source) -> key;
ResultBuilder
© 2015 - 2024 Weber Informatics LLC | Privacy Policy