@Test public void testAddIndexSourceMissingValues() throws Exception { JCas cas = JCasFactory.createJCas("de.julielab.jcore.consumer.es.testTypes"); cas.setDocumentText("Black Beauty ran past the bloody barn."); new TokenTestType(cas, 0, 5).addToIndexes(); new TokenTestType(cas, 6, 12).addToIndexes(); new TokenTestType(cas, 13, 16).addToIndexes(); new TokenTestType(cas, 17, 21).addToIndexes(); new TokenTestType(cas, 22, 25).addToIndexes(); new TokenTestType(cas, 26, 32).addToIndexes(); new TokenTestType(cas, 33, 37).addToIndexes(); new TokenTestType(cas, 37, 38).addToIndexes(); EntityTestType e = new EntityTestType(cas, 0, 12); e.setEntityType("hero"); e.addToIndexes(); ESConsumerTestType esctt = new ESConsumerTestType(cas, 26, 37); StringArray sa = new StringArray(cas, 2); sa.set(0, "NP"); sa.set(1, "NNP"); esctt.setStringArrayFeature(sa); esctt.addToIndexes(); HeaderTestType header = new HeaderTestType(cas); header.addToIndexes(); TestFieldGeneratorBlackBeauty generator = new TestFieldGeneratorBlackBeauty(); Document document = generator.addFields(cas, new Document()); ElasticSearchConsumer consumer = new ElasticSearchConsumer(); System.setProperty("ES_CONSUMER_TEST_MODE", "true"); consumer.initialize(UimaContextFactory.createUimaContext()); Method method = ElasticSearchConsumer.class.getDeclaredMethod("createIndexSource", Document.class); method.setAccessible(true); String indexSource = (String) method.invoke(consumer, document); assertEquals( "{\"text\":\"{\\\"v\\\":\\\"1\\\",\\\"str\\\":\\\"Black Beauty ran past the bloody barn.\\\",\\\"tokens\\\":[{\\\"t\\\":\\\"Black\\\",\\\"s\\\":0,\\\"e\\\":5,\\\"i\\\":1},{\\\"t\\\":\\\"hero\\\",\\\"s\\\":0,\\\"e\\\":12,\\\"i\\\":0},{\\\"t\\\":\\\"Beauty\\\",\\\"s\\\":6,\\\"e\\\":12,\\\"i\\\":1},{\\\"t\\\":\\\"ran\\\",\\\"s\\\":13,\\\"e\\\":16,\\\"i\\\":1},{\\\"t\\\":\\\"past\\\",\\\"s\\\":17,\\\"e\\\":21,\\\"i\\\":1},{\\\"t\\\":\\\"the\\\",\\\"s\\\":22,\\\"e\\\":25,\\\"i\\\":1},{\\\"t\\\":\\\"bloody\\\",\\\"s\\\":26,\\\"e\\\":32,\\\"i\\\":1},{\\\"t\\\":\\\"NP\\\",\\\"s\\\":26,\\\"e\\\":37,\\\"i\\\":0},{\\\"t\\\":\\\"NNP\\\",\\\"s\\\":26,\\\"e\\\":37,\\\"i\\\":0},{\\\"t\\\":\\\"barn\\\",\\\"s\\\":33,\\\"e\\\":37,\\\"i\\\":1},{\\\"t\\\":\\\".\\\",\\\"s\\\":37,\\\"e\\\":38,\\\"i\\\":1}]}\"}", indexSource); }
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); urls = (String[]) getContext().getConfigParameterValue(PARAM_URLS); indexName = (String) getContext().getConfigParameterValue(PARAM_INDEX_NAME); type = (String) getContext().getConfigParameterValue(PARAM_TYPE); batchSize = Optional.ofNullable((Integer) getContext().getConfigParameterValue(PARAM_BATCH_SIZE)).orElse(50); bulkCommand = new ArrayList<>(4000); httpclient = HttpClientBuilder.create().build(); if (urls != null) { indexPosts = new HttpPost[urls.length]; for (int i = 0; i < urls.length; i++) { String url = urls[i]; if (null != url && !url.endsWith("/_bulk")) url = url + "/_bulk"; indexPosts[i] = new HttpPost(url); indexPosts[i].addHeader("Content-Type", "application/x-ndjson"); } } if (log.isInfoEnabled()) { log.info("{}: {}", PARAM_URLS, Arrays.toString(urls)); log.info("{}: {}", PARAM_INDEX_NAME, indexName); log.info("{}: {}", PARAM_TYPE, type); } }
ElasticSearchConsumer extends AbstractCasToJsonConsumer { @Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); urls = (String[]) getContext().getConfigParameterValue(PARAM_URLS); indexName = (String) getContext().getConfigParameterValue(PARAM_INDEX_NAME); type = (String) getContext().getConfigParameterValue(PARAM_TYPE); batchSize = Optional.ofNullable((Integer) getContext().getConfigParameterValue(PARAM_BATCH_SIZE)).orElse(50); bulkCommand = new ArrayList<>(4000); httpclient = HttpClientBuilder.create().build(); if (urls != null) { indexPosts = new HttpPost[urls.length]; for (int i = 0; i < urls.length; i++) { String url = urls[i]; if (null != url && !url.endsWith("/_bulk")) url = url + "/_bulk"; indexPosts[i] = new HttpPost(url); indexPosts[i].addHeader("Content-Type", "application/x-ndjson"); } } if (log.isInfoEnabled()) { log.info("{}: {}", PARAM_URLS, Arrays.toString(urls)); log.info("{}: {}", PARAM_INDEX_NAME, indexName); log.info("{}: {}", PARAM_TYPE, type); } } }
ElasticSearchConsumer extends AbstractCasToJsonConsumer { @Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); urls = (String[]) getContext().getConfigParameterValue(PARAM_URLS); indexName = (String) getContext().getConfigParameterValue(PARAM_INDEX_NAME); type = (String) getContext().getConfigParameterValue(PARAM_TYPE); batchSize = Optional.ofNullable((Integer) getContext().getConfigParameterValue(PARAM_BATCH_SIZE)).orElse(50); bulkCommand = new ArrayList<>(4000); httpclient = HttpClientBuilder.create().build(); if (urls != null) { indexPosts = new HttpPost[urls.length]; for (int i = 0; i < urls.length; i++) { String url = urls[i]; if (null != url && !url.endsWith("/_bulk")) url = url + "/_bulk"; indexPosts[i] = new HttpPost(url); indexPosts[i].addHeader("Content-Type", "application/x-ndjson"); } } if (log.isInfoEnabled()) { log.info("{}: {}", PARAM_URLS, Arrays.toString(urls)); log.info("{}: {}", PARAM_INDEX_NAME, indexName); log.info("{}: {}", PARAM_TYPE, type); } }  }
ElasticSearchConsumer extends AbstractCasToJsonConsumer { @Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); urls = (String[]) getContext().getConfigParameterValue(PARAM_URLS); indexName = (String) getContext().getConfigParameterValue(PARAM_INDEX_NAME); type = (String) getContext().getConfigParameterValue(PARAM_TYPE); batchSize = Optional.ofNullable((Integer) getContext().getConfigParameterValue(PARAM_BATCH_SIZE)).orElse(50); bulkCommand = new ArrayList<>(4000); httpclient = HttpClientBuilder.create().build(); if (urls != null) { indexPosts = new HttpPost[urls.length]; for (int i = 0; i < urls.length; i++) { String url = urls[i]; if (null != url && !url.endsWith("/_bulk")) url = url + "/_bulk"; indexPosts[i] = new HttpPost(url); indexPosts[i].addHeader("Content-Type", "application/x-ndjson"); } } if (log.isInfoEnabled()) { log.info("{}: {}", PARAM_URLS, Arrays.toString(urls)); log.info("{}: {}", PARAM_INDEX_NAME, indexName); log.info("{}: {}", PARAM_TYPE, type); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas aJCas); void customBatchProcessComplete(); @Override void collectionProcessComplete(); }
ElasticSearchConsumer extends AbstractCasToJsonConsumer { @Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); urls = (String[]) getContext().getConfigParameterValue(PARAM_URLS); indexName = (String) getContext().getConfigParameterValue(PARAM_INDEX_NAME); type = (String) getContext().getConfigParameterValue(PARAM_TYPE); batchSize = Optional.ofNullable((Integer) getContext().getConfigParameterValue(PARAM_BATCH_SIZE)).orElse(50); bulkCommand = new ArrayList<>(4000); httpclient = HttpClientBuilder.create().build(); if (urls != null) { indexPosts = new HttpPost[urls.length]; for (int i = 0; i < urls.length; i++) { String url = urls[i]; if (null != url && !url.endsWith("/_bulk")) url = url + "/_bulk"; indexPosts[i] = new HttpPost(url); indexPosts[i].addHeader("Content-Type", "application/x-ndjson"); } } if (log.isInfoEnabled()) { log.info("{}: {}", PARAM_URLS, Arrays.toString(urls)); log.info("{}: {}", PARAM_INDEX_NAME, indexName); log.info("{}: {}", PARAM_TYPE, type); } }  @Override void initialize(UimaContext aContext); @Override void process(JCas aJCas); void customBatchProcessComplete(); @Override void collectionProcessComplete(); static final String PARAM_URLS; static final String PARAM_INDEX_NAME; static final String PARAM_TYPE; static final String PARAM_BATCH_SIZE; }