Java Code Examples for org.elasticsearch.client.Requests#indexRequest()
The following examples show how to use
org.elasticsearch.client.Requests#indexRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticSearchSink.java From pulsar with Apache License 2.0 | 6 votes |
@Override public void write(Record<byte[]> record) { KeyValue<String, byte[]> keyValue = extractKeyValue(record); IndexRequest indexRequest = Requests.indexRequest(elasticSearchConfig.getIndexName()); indexRequest.type(elasticSearchConfig.getTypeName()); indexRequest.source(keyValue.getValue(), XContentType.JSON); try { IndexResponse indexResponse = getClient().index(indexRequest); if (indexResponse.getResult().equals(DocWriteResponse.Result.CREATED)) { record.ack(); } else { record.fail(); } } catch (final IOException ex) { record.fail(); } }
Example 2
Source File: JLineRhinoCompleterTest.java From elasticshell with Apache License 2.0 | 4 votes |
@Test public void testCompleteNestedNativeJavaObject() { NativeJavaObject nativeJavaObject = new RhinoCustomNativeJavaObject(completer.getScope().get(), Requests.indexRequest("index_name"), IndexRequest.class); nativeJavaObject.setPrototype(Context.getCurrentContext().newObject(completer.getScope().get())); NativeJavaObject nestedDativeJavaObject = new RhinoCustomNativeJavaObject(completer.getScope().get(), Requests.indexRequest("index_name"), IndexRequest.class); nestedDativeJavaObject.setPrototype(Context.getCurrentContext().newObject(completer.getScope().get())); ScriptableObject.putProperty(nativeJavaObject, "typeNested", nestedDativeJavaObject); completer.getScope().registerJavaObject("ir", nativeJavaObject); List<CharSequence> candidates = new ArrayList<CharSequence>(); String input = "ir.ty"; int output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("type()")); Assert.assertTrue(candidates.contains("typeNested")); Assert.assertEquals(output, 3); candidates.clear(); input = "ir.type('type_name').id"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 1); Assert.assertEquals(candidates.get(0), "id()"); Assert.assertEquals(output, 21); candidates.clear(); input = "ir.type('type_name').id(\"id\").so"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("source()")); Assert.assertTrue(candidates.contains("sourceAsMap()")); Assert.assertEquals(output, 30); candidates.clear(); input = "ir.typeNested.ty"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 1); Assert.assertEquals(candidates.get(0), "type()"); Assert.assertEquals(output, 14); candidates.clear(); input = "ir.typeNested.type('type_name').id"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 1); Assert.assertEquals(candidates.get(0), "id()"); Assert.assertEquals(output, 32); candidates.clear(); input = "ir.typeNested.type('type_name').id(\"id\").so"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("source()")); Assert.assertTrue(candidates.contains("sourceAsMap()")); Assert.assertEquals(output, 41); }
Example 3
Source File: JLineRhinoCompleterTest.java From elasticshell with Apache License 2.0 | 4 votes |
@Test public void testCompleteNestedNativeJavaObjectNonJavaIdentifier() { NativeJavaObject nativeJavaObject = new RhinoCustomNativeJavaObject(completer.getScope().get(), Requests.indexRequest("index_name"), IndexRequest.class); nativeJavaObject.setPrototype(Context.getCurrentContext().newObject(completer.getScope().get())); NativeJavaObject nestedDativeJavaObject = new RhinoCustomNativeJavaObject(completer.getScope().get(), Requests.indexRequest("index_name"), IndexRequest.class); nestedDativeJavaObject.setPrototype(Context.getCurrentContext().newObject(completer.getScope().get())); ScriptableObject.putProperty(nativeJavaObject, "type-name", nestedDativeJavaObject); completer.getScope().registerJavaObject("ir", nativeJavaObject); List<CharSequence> candidates = new ArrayList<CharSequence>(); String input = "ir.ty"; int output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("type()")); Assert.assertTrue(candidates.contains("type-name")); Assert.assertEquals(output, 3); candidates.clear(); input = "ir.type('type_name').id"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 1); Assert.assertEquals(candidates.get(0), "id()"); Assert.assertEquals(output, 21); candidates.clear(); input = "ir.type('type_name').id(\"id\").so"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("source()")); Assert.assertTrue(candidates.contains("sourceAsMap()")); Assert.assertEquals(output, 30); candidates.clear(); input = "ir['type-name'].ty"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 1); Assert.assertEquals(candidates.get(0), "type()"); Assert.assertEquals(output, 16); candidates.clear(); input = "ir['type-name'].type('type_name').id(\"id\").so"; output = completer.complete(input, input.length(), candidates); Assert.assertEquals(candidates.size(), 2); Assert.assertTrue(candidates.contains("source()")); Assert.assertTrue(candidates.contains("sourceAsMap()")); Assert.assertEquals(output, 43); }