如何在Elasticsearch Java Bulk Api中添加路径参数>> [

问题描述 投票:0回答:1
我正在使用Java批量Api,Elasticsearch 6.6.2,并且希望以POST /<index>/_bulk,但我却得到了POST /_bulk(请参阅下面的数据包)。

[我知道这2种POST方法是相同的,但是我的应用程序和ES之间有一个代理,出于某些原因,path参数用于该代理(我不知道为什么)。

所以,我想知道如何在Java中设置path parameter,以便可以POST /<index>/_bulk格式发送请求。

这里是代码

RestHighLevelClient client; /* some client init code ....*/ ... String INDEX = "api_track"; String DOC_TYPE = "_doc"; BulkProcessor.Builder builder = BulkProcessor.builder( (request, bulkListener) -> client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener), listener); builder.setBulkActions(500); builder.setBulkSize(new ByteSizeValue(1L, ByteSizeUnit.MB)); builder.setConcurrentRequests(0); builder.setFlushInterval(TimeValue.timeValueSeconds(5L)); builder.setBackoffPolicy(BackoffPolicy .constantBackoff(TimeValue.timeValueSeconds(1L), 3)); builder.setGlobalIndex(INDEX); builder.setGlobalType(DOC_TYPE); bulkProcessor = builder.build(); IndexRequest request = new IndexRequest().index(INDEX).type(DOC_TYPE).source(maps); bulkProcessor.add(request);

和捕获的数据包:

0x0000: 0200 0000 4500 0277 0000 4000 4006 12c9 ....E..w..@.@... 0x0010: 1e27 dee3 0ba3 1d0b e142 23f0 85d1 ad67 .'.......B#....g 0x0020: 1540 31d3 8018 0801 3eb0 0000 0101 080a .@1.....>....... 0x0030: 1500 c5e6 b6ba 7ff0 504f 5354 202f 5f62 ........POST./_b <-- POST format here 0x0040: 756c 6b3f 7469 6d65 6f75 743d 316d 2048 ulk?timeout=1m.H 0x0050: 5454 502f 312e 310d 0a43 6f6e 7465 6e74 TTP/1.1..Content 0x0060: 2d4c 656e 6774 683a 2033 3335 0d0a 436f -Length:.335..Co 0x0070: 6e74 656e 742d 5479 7065 3a20 6170 706c ntent-Type:.appl 0x0080: 6963 6174 696f 6e2f 6a73 6f6e 0d0a 486f ication/json..Ho 0x0090: 7374 3a20 7365 6172 6368 2e61 6c69 7061 st:.search.alipa 0x00a0: 792e 6e65 743a 3932 3030 0d0a 436f 6e6e y.net:9200..Conn 0x00b0: 6563 7469 6f6e 3a20 4b65 6570 2d41 6c69 ection:.Keep-Ali 0x00c0: 7665 0d0a 5573 6572 2d41 6765 6e74 3a20 ve..User-Agent:. 0x00d0: 4170 6163 6865 2d48 7474 7041 7379 6e63 Apache-HttpAsync 0x00e0: 436c 6965 6e74 2f34 2e31 2e34 2028 4a61 Client/4.1.4.(Ja 0x00f0: 7661 2f31 2e38 2e30 5f31 3531 290d 0a41 va/1.8.0_151)..A 0x0100: 7574 686f 7269 7a61 7469 6f6e 3a20 4261 uthorization:.Ba 0x0110: 7369 6320 6247 6c75 6132 4d36 527a 4e61 sic.bGlua2M6RzNa 0x0120: 5954 4e4e 5755 593d 0d0a 0d0a 7b22 696e YTNNWUY=....{"in 0x0130: 6465 7822 3a7b 225f 696e 6465 7822 3a22 dex":{"_index":" 0x0140: 6170 695f 7472 6163 6b22 2c22 5f74 7970 api_track","_typ 0x0150: 6522 3a22 5f64 6f63 227d 7d0a 7b22 6372 e":"_doc"}}.{"cr 0x0160: 6561 7465 6441 7422 3a22 3230 3230 2d30 eatedAt":"2020-0 0x0170: 322d 3132 5430 383a 3438 3a34 332e 3333 2-12T08:48:43.33 0x0180: 3822 2c22 686f 7374 4164 6472 223a 2231 8","hostAddr":"1 0x0190: 3237 2e30 2e30 2e31 222c 2274 656e 616e 27.0.0.1","tenan 0x01a0: 7449 6422 3a6e 756c 6c2c 2273 6572 7665 tId":null,"serve 0x01b0: 724e 616d 6522 3a6e 756c 6c2c 2270 6172 rName":null,"par 0x01c0: 616d 7322 3a22 2670 7269 7661 7465 5f74 ams":"&private_t 0x01d0: 6f6b 656e 3d2a 2a2a 266f 7264 6572 5f62 oken=***&order_b 0x01e0: 793d 7369 7a65 222c 2275 7365 724e 616d y=size","userNam 0x01f0: 6522 3a22 6d79 7363 6d22 2c22 7573 6572 e":"myscm","user 0x0200: 4964 223a 3330 3034 2c22 7061 7468 6e61 Id":3004,"pathna 0x0210: 6d65 223a 222f 6170 692f 7634 2f70 726f me":"/api/v4/pro 0x0220: 6a65 6374 732f 3339 3235 352f 6c61 6e67 jects/39255/lang 0x0230: 7561 6765 7322 2c22 7265 6d6f 7465 4164 uages","remoteAd 0x0240: 6472 223a 2233 302e 3339 2e32 3232 2e32 dr":"30.39.222.2 0x0250: 3237 222c 2275 7064 6174 6564 4174 223a 27","updatedAt": 0x0260: 2232 3032 302d 3032 2d31 3254 3038 3a34 "2020-02-12T08:4 0x0270: 383a 3433 2e33 3338 227d 0a 8:43.338"}.

我正在使用Java批量Api,Elasticsearch 6.6.2,并希望将POST批量请求发布为POST / 

/ _ bulk,但是我却获得了POST / _bulk(请参阅下面的数据包)。我知道这2个POST方法是...

elasticsearch resthighlevelclient
1个回答
0
投票
可以通过client.getLowLevelClient().performRequest(new Request(method, endpoint))完成,将INDEX填充到method的参数中。
© www.soinside.com 2019 - 2024. All rights reserved.