@Test public void testCustomMappingProperty() throws BackendException, IOException, ParseException, URISyntaxException { String mappingTypeName = "vertex"; String indexPrefix = "janusgraph"; String parameterName = "boost"; Double parameterValue = 5.5; String field = "field_with_custom_prop"; KeyInformation keyInfo = new StandardKeyInformation( String.class, Cardinality.SINGLE, Mapping.STRING.asParameter(), Parameter.of(ParameterType.customParameterName(parameterName), parameterValue)); index.register(mappingTypeName, field, keyInfo, tx); String indexName = indexPrefix+"_"+mappingTypeName; CloseableHttpResponse response = getESMapping(indexName, mappingTypeName); if(response.getStatusLine().getStatusCode() != 200){ indexName = indexPrefix; response = getESMapping(indexName, mappingTypeName); } HttpEntity entity = response.getEntity(); JSONObject json = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity)); String returnedProperty; if(JanusGraphElasticsearchContainer.getEsMajorVersion().value < 7){ returnedProperty = retrieveValueFromJSON(json, indexName, "mappings", mappingTypeName, "properties", field, parameterName); } else { returnedProperty = retrieveValueFromJSON(json, indexName, "mappings", "properties", field, parameterName); } assertEquals(parameterValue.toString(), returnedProperty); IOUtils.closeQuietly(response); }
@Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { final Class<?> dataType = information.getDataType(); final Mapping map = Mapping.getMapping(information); Preconditions.checkArgument(map==Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]",map,dataType); final String indexStoreName = getIndexStoreName(store); if (useExternalMappings) { try { final IndexMapping mappings = client.getMapping(indexStoreName, store); if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) { throw new PermanentBackendException("The external mapping for index '"+ indexStoreName + "' and type '" + store + "' do not have property '" + key + "'"); } else if (allowMappingUpdate && mappings.isDynamic()) { this.pushMapping(store, key, information); } } catch (final IOException e) { throw new PermanentBackendException(e); } } else { try { checkForOrCreateIndex(indexStoreName); } catch (final IOException e) { throw new PermanentBackendException(e); } this.pushMapping(store, key, information); } }
ElasticSearchIndex implements IndexProvider { @Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { final Class<?> dataType = information.getDataType(); final Mapping map = Mapping.getMapping(information); Preconditions.checkArgument(map==Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]",map,dataType); final String indexStoreName = getIndexStoreName(store); if (useExternalMappings) { try { final IndexMapping mappings = client.getMapping(indexStoreName, store); if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) { throw new PermanentBackendException("The external mapping for index '"+ indexStoreName + "' and type '" + store + "' do not have property '" + key + "'"); } else if (allowMappingUpdate && mappings.isDynamic()) { this.pushMapping(store, key, information); } } catch (final IOException e) { throw new PermanentBackendException(e); } } else { try { checkForOrCreateIndex(indexStoreName); } catch (final IOException e) { throw new PermanentBackendException(e); } this.pushMapping(store, key, information); } } }
ElasticSearchIndex implements IndexProvider { @Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { final Class<?> dataType = information.getDataType(); final Mapping map = Mapping.getMapping(information); Preconditions.checkArgument(map==Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]",map,dataType); final String indexStoreName = getIndexStoreName(store); if (useExternalMappings) { try { final IndexMapping mappings = client.getMapping(indexStoreName, store); if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) { throw new PermanentBackendException("The external mapping for index '"+ indexStoreName + "' and type '" + store + "' do not have property '" + key + "'"); } else if (allowMappingUpdate && mappings.isDynamic()) { this.pushMapping(store, key, information); } } catch (final IOException e) { throw new PermanentBackendException(e); } } else { try { checkForOrCreateIndex(indexStoreName); } catch (final IOException e) { throw new PermanentBackendException(e); } this.pushMapping(store, key, information); } } ElasticSearchIndex(Configuration config); }
ElasticSearchIndex implements IndexProvider { @Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { final Class<?> dataType = information.getDataType(); final Mapping map = Mapping.getMapping(information); Preconditions.checkArgument(map==Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]",map,dataType); final String indexStoreName = getIndexStoreName(store); if (useExternalMappings) { try { final IndexMapping mappings = client.getMapping(indexStoreName, store); if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) { throw new PermanentBackendException("The external mapping for index '"+ indexStoreName + "' and type '" + store + "' do not have property '" + key + "'"); } else if (allowMappingUpdate && mappings.isDynamic()) { this.pushMapping(store, key, information); } } catch (final IOException e) { throw new PermanentBackendException(e); } } else { try { checkForOrCreateIndex(indexStoreName); } catch (final IOException e) { throw new PermanentBackendException(e); } this.pushMapping(store, key, information); } } ElasticSearchIndex(Configuration config); @Override void register(String store, String key, KeyInformation information,
                         BaseTransaction tx); Map<String, Object> getNewDocument(final List<IndexEntry> additions,
                                              KeyInformation.StoreRetriever information); @Override void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever information,
                       BaseTransaction tx); @Override void restore(Map<String,Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever information,
                        BaseTransaction tx); Map<String,Object> getFilter(Condition<?> condition, KeyInformation.StoreRetriever information); @Override Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever informations,
                                BaseTransaction tx); @Override Stream<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever information,
                                                 BaseTransaction tx); @Override Long totals(RawQuery query, KeyInformation.IndexRetriever information,
                       BaseTransaction tx); @Override boolean supports(KeyInformation information, JanusGraphPredicate janusgraphPredicate); @Override boolean supports(KeyInformation information); @Override String mapKey2Field(String key, KeyInformation information); @Override IndexFeatures getFeatures(); @Override BaseTransactionConfigurable beginTransaction(BaseTransactionConfig config); @Override void close(); @Override void clearStorage(); @Override boolean exists(); }
ElasticSearchIndex implements IndexProvider { @Override public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException { final Class<?> dataType = information.getDataType(); final Mapping map = Mapping.getMapping(information); Preconditions.checkArgument(map==Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map==Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]",map,dataType); final String indexStoreName = getIndexStoreName(store); if (useExternalMappings) { try { final IndexMapping mappings = client.getMapping(indexStoreName, store); if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) { throw new PermanentBackendException("The external mapping for index '"+ indexStoreName + "' and type '" + store + "' do not have property '" + key + "'"); } else if (allowMappingUpdate && mappings.isDynamic()) { this.pushMapping(store, key, information); } } catch (final IOException e) { throw new PermanentBackendException(e); } } else { try { checkForOrCreateIndex(indexStoreName); } catch (final IOException e) { throw new PermanentBackendException(e); } this.pushMapping(store, key, information); } } ElasticSearchIndex(Configuration config); @Override void register(String store, String key, KeyInformation information,
                         BaseTransaction tx); Map<String, Object> getNewDocument(final List<IndexEntry> additions,
                                              KeyInformation.StoreRetriever information); @Override void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever information,
                       BaseTransaction tx); @Override void restore(Map<String,Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever information,
                        BaseTransaction tx); Map<String,Object> getFilter(Condition<?> condition, KeyInformation.StoreRetriever information); @Override Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever informations,
                                BaseTransaction tx); @Override Stream<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever information,
                                                 BaseTransaction tx); @Override Long totals(RawQuery query, KeyInformation.IndexRetriever information,
                       BaseTransaction tx); @Override boolean supports(KeyInformation information, JanusGraphPredicate janusgraphPredicate); @Override boolean supports(KeyInformation information); @Override String mapKey2Field(String key, KeyInformation information); @Override IndexFeatures getFeatures(); @Override BaseTransactionConfigurable beginTransaction(BaseTransactionConfig config); @Override void close(); @Override void clearStorage(); @Override boolean exists(); static final ConfigNamespace ELASTICSEARCH_NS; static final ConfigOption<String> INTERFACE; static final ConfigOption<String> HEALTH_REQUEST_TIMEOUT; static final ConfigOption<String> BULK_REFRESH; static final ConfigNamespace ES_CREATE_NS; static final ConfigOption<Long> CREATE_SLEEP; static final ConfigNamespace ES_CREATE_EXTRAS_NS; static final ConfigOption<Boolean> USE_EXTERNAL_MAPPINGS; static final ConfigOption<Integer> NUMBER_OF_REPLICAS; static final ConfigOption<Integer> NUMBER_OF_SHARDS; static final ConfigOption<Boolean> ALLOW_MAPPING_UPDATE; static final ConfigOption<Boolean> USE_ALL_FIELD; static final ConfigOption<Integer> ES_SCROLL_KEEP_ALIVE; static final ConfigNamespace ES_INGEST_PIPELINES; static final ConfigNamespace SSL_NS; static final ConfigOption<Boolean> SSL_ENABLED; static final ConfigOption<Boolean> SSL_DISABLE_HOSTNAME_VERIFICATION; static final ConfigOption<Boolean> SSL_ALLOW_SELF_SIGNED_CERTIFICATES; static final ConfigNamespace SSL_TRUSTSTORE_NS; static final ConfigOption<String> SSL_TRUSTSTORE_LOCATION; static final ConfigOption<String> SSL_TRUSTSTORE_PASSWORD; static final ConfigNamespace SSL_KEYSTORE_NS; static final ConfigOption<String> SSL_KEYSTORE_LOCATION; static final ConfigOption<String> SSL_KEYSTORE_PASSWORD; static final ConfigOption<String> SSL_KEY_PASSWORD; static final ConfigNamespace ES_HTTP_NS; static final ConfigNamespace ES_HTTP_AUTH_NS; static final ConfigOption<String> ES_HTTP_AUTH_TYPE; static final ConfigNamespace ES_HTTP_AUTH_BASIC_NS; static final ConfigOption<String> ES_HTTP_AUTH_USERNAME; static final ConfigOption<String> ES_HTTP_AUTH_PASSWORD; static final ConfigOption<String> ES_HTTP_AUTH_REALM; static final ConfigNamespace ES_HTTP_AUTH_CUSTOM_NS; static final ConfigOption<String> ES_HTTP_AUTHENTICATOR_CLASS; static final ConfigOption<String[]> ES_HTTP_AUTHENTICATOR_ARGS; static final ConfigOption<Boolean> SETUP_MAX_OPEN_SCROLL_CONTEXTS; static final ConfigOption<Boolean> USE_MAPPING_FOR_ES7; static final ConfigOption<Long> CLIENT_KEEP_ALIVE; static final ConfigOption<Integer> RETRY_ON_CONFLICT; static final ConfigOption<Boolean> ENABLE_INDEX_STORE_NAMES_CACHE; static final int HOST_PORT_DEFAULT; static final int DEFAULT_GEO_MAX_LEVELS; static final double DEFAULT_GEO_DIST_ERROR_PCT; }