ElasticSearchIndexProvider implements IndexProvider { public IndexRequestBuilder createIndexRequest(ElasticMetaObject object) { String clusterId = ((ElasticMetaProperty) object.getProperty(MetaObject.META_OBJECT_CLUSTER_ID).get()).getValue().toLowerCase(); String type = ((ElasticMetaProperty) object.getProperty(MetaObject.META_OBJECT_TYPE).get()).getValue().toLowerCase(); Map<String, Object> document = object.getProperties().stream() .map(metaProperty -> ((ElasticMetaProperty) metaProperty)) .collect(Collectors.toMap(ElasticMetaProperty::getName, ElasticMetaProperty::getValue, (mp1, mp2) -> mp2)); return this.getClient().prepareIndex(sanitizeIndex(clusterId), sanitizeIndex(type)).setSource(document); } ElasticSearchIndexProvider(MetaModelStore metaModelStore,
                                      ElasticSearchContext elasticSearchContext,
                                      Analyzer analyzer); Client getClient(); @Override boolean isFreshIndex(KCluster cluster); @Override void index(KObject object); @Override void index(List<KObject> elements); IndexRequestBuilder createIndexRequest(ElasticMetaObject object); @Override boolean exists(String index,
                          String id); @Override void delete(String index); @Override void delete(String index,
                       String id); @Override List<KObject> findById(String index,
                                  String id); @Override void rename(String index,
                       String id,
                       KObject to); @Override long getIndexSize(String index); @Override List<KObject> findByQuery(List<String> indices,
                                     Query query,
                                     int limit); @Override List<KObject> findByQuery(List<String> indices,
                                     Query query,
                                     Sort sort,
                                     int limit); @Override long findHitsByQuery(List<String> indices,
                                Query query); @Override List<String> getIndices(); @Override void observerInitialization(Runnable runnable); @Override boolean isAlive(); void putMapping(String index,
                           String type,
                           MetaObject metaObject); Optional<MappingMetaData> getMapping(String index,
                                                String type); void putMapping(String index,
                           String type,
                           List<MetaProperty> metaProperties); @Override void dispose(); static final int ELASTICSEARCH_MAX_SIZE; static final String ES_TEXT_TYPE; static final String ES_KEYWORD_TYPE; }
@Test public void testCreateIndexRequest() { ElasticMetaObject obj = new ElasticMetaObject(() -> "type"); obj.addProperty(new ElasticMetaProperty("cluster.id", "system_ou/plugins", Sets.newHashSet(String.class))); obj.addProperty(new ElasticMetaProperty("type", "plugins", Sets.newHashSet(String.class))); this.provider.createIndexRequest(obj); verify(transportClient).prepareIndex(eq("system_ou_plugins"), eq("plugins")); }