ElasticSearchConsumer extends AbstractCasToJsonConsumer { private void addIndexSource(Document doc) { bulkCommand.add(createIndexSource(doc)); }  @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; }
@Test public void testAddIndexSource() 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); AuthorTestType author1 = new AuthorTestType(cas); author1.setFirstname("Anna"); author1.setLastname("Sewell"); AddressTestType address1 = new AddressTestType(cas); address1.setStreet("42nd Street"); address1.setNumber(47); address1.setCity("London"); author1.setAuthorAddress(address1); AuthorTestType author2 = new AuthorTestType(cas); author2.setFirstname("No"); author2.setLastname("One"); AddressTestType address2 = new AddressTestType(cas); address2.setCity("Cambridge"); author2.setAuthorAddress(address2); FSArray authorArray = new FSArray(cas, 2); authorArray.set(0, author1); authorArray.set(1, author2); header.setTestAuthors(authorArray); header.addToIndexes(); TestFieldGeneratorBlackBeauty generator = new TestFieldGeneratorBlackBeauty(); Document document = generator.addFields(cas, new Document()); System.setProperty("ES_CONSUMER_TEST_MODE", "true"); ElasticSearchConsumer consumer = new ElasticSearchConsumer(); consumer.initialize(UimaContextFactory.createUimaContext()); Method method = ElasticSearchConsumer.class.getDeclaredMethod("createIndexSource", Document.class); method.setAccessible(true); String indexSource = (String) method.invoke(consumer, document); assertEquals( "{\"structuredAuthor\":[{\"firstname\":\"Anna\",\"address\":{\"number\":47,\"city\":\"London\",\"street\":\"42nd Street\"},\"lastname\":\"Sewell\"},{\"firstname\":\"No\",\"address\":{\"number\":0,\"city\":\"Cambridge\"},\"lastname\":\"One\"}],\"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}]}\",\"authors\":[\"Sewell, Anna\",\"One, No\"]}", indexSource); }