You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/01/15 00:46:35 UTC

[GitHub] MikeThomsen commented on a change in pull request #3268: NIFI-5947 Elasticsearch lookup service compatible with LookupAttribute

MikeThomsen commented on a change in pull request #3268: NIFI-5947 Elasticsearch lookup service compatible with LookupAttribute
URL: https://github.com/apache/nifi/pull/3268#discussion_r247724378
 
 

 ##########
 File path: nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchStringLookupService.java
 ##########
 @@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.elasticsearch;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.lookup.LookupFailureException;
+import org.apache.nifi.lookup.StringLookupService;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+public class ElasticSearchStringLookupService extends AbstractControllerService implements StringLookupService {
+    public static final PropertyDescriptor CLIENT_SERVICE = new PropertyDescriptor.Builder()
+            .name("el-rest-client-service")
+            .displayName("Client Service")
+            .description("An ElasticSearch client service to use for running queries.")
+            .identifiesControllerService(ElasticSearchClientService.class)
+            .required(true)
+            .build();
+    public static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+            .name("el-lookup-index")
+            .displayName("Index")
+            .description("The name of the index to read from")
+            .required(true)
+            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+    public static final PropertyDescriptor TYPE = new PropertyDescriptor.Builder()
+            .name("el-lookup-type")
+            .displayName("Type")
+            .description("The type of this document (used by Elasticsearch for indexing and searching)")
+            .required(false)
+            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+    private static final List<PropertyDescriptor> DESCRIPTORS = Arrays.asList(CLIENT_SERVICE, INDEX, TYPE);
+    private static final ObjectMapper mapper = new ObjectMapper();
+    private static final String ID = "id";
+    private ElasticSearchClientService esClient;
+    private String index;
+    private String type;
+
+    @Override
+    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) {
+        esClient = context.getProperty(CLIENT_SERVICE).asControllerService(ElasticSearchClientService.class);
+        index = context.getProperty(INDEX).evaluateAttributeExpressions().getValue();
+        type = context.getProperty(TYPE).evaluateAttributeExpressions().getValue();
+    }
+
+    @Override
+    public Optional<String> lookup(Map<String, Object> coordinates) throws LookupFailureException {
+        try {
+            final String id = (String) coordinates.get(ID);
+            final Map<String, Object> enums = esClient.get(index, type, id);
 
 Review comment:
   How do you envision users figuring out which document they need for the enrichment?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services