Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2017 JanusGraph Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.janusgraph.diskstorage.es.compat;
import static org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_ANALYZER;
import static org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_INLINE_KEY;
import static org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_LANG_KEY;
import static org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_SCRIPT_KEY;
import static org.janusgraph.diskstorage.es.ElasticSearchConstants.ES_TYPE_KEY;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.attribute.Geo;
import org.janusgraph.core.schema.Mapping;
import org.janusgraph.core.schema.Parameter;
import org.janusgraph.diskstorage.es.ElasticSearchRequest;
import org.janusgraph.diskstorage.indexing.IndexFeatures;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
* Base class for building Elasticsearch mapping and query objects.
*/
public abstract class AbstractESCompat {
static final Map MATCH_ALL = ImmutableMap.of("match_all", Collections.EMPTY_MAP);
static IndexFeatures.Builder coreFeatures() {
return new IndexFeatures.Builder()
.setDefaultStringMapping(Mapping.TEXT)
.supportedStringMappings(Mapping.TEXT, Mapping.TEXTSTRING, Mapping.STRING)
.setWildcardField("_all")
.supportsCardinality(Cardinality.SINGLE)
.supportsCardinality(Cardinality.LIST)
.supportsCardinality(Cardinality.SET)
.supportsNanoseconds()
.supportsCustomAnalyzer()
.supportNotQueryNormalForm()
;
}
public abstract IndexFeatures getIndexFeatures();
public Map createKeywordMapping() {
return ImmutableMap.of(ES_TYPE_KEY, "keyword");
}
public Map createTextMapping(String textAnalyzer) {
final ImmutableMap.Builder builder = ImmutableMap.builder().put(ES_TYPE_KEY, "text");
return (textAnalyzer != null ? builder.put(ES_ANALYZER, textAnalyzer) : builder).build();
}
public String scriptLang() {
return "painless";
}
public ImmutableMap.Builder prepareScript(String inline) {
final Map script = ImmutableMap.of(ES_INLINE_KEY, inline, ES_LANG_KEY, scriptLang());
return ImmutableMap.builder().put(ES_SCRIPT_KEY, script);
}
public Map prepareQuery(Map query) {
return query;
}
public Map term(String key, Object value) {
return ImmutableMap.of("term", ImmutableMap.of(key, value));
}
public Map contains(String key, List terms) {
return boolMust(terms.stream().map(term -> term(key, term)).collect(Collectors.toList()));
}
public Map boolMust(List