Java Code Examples for org.elasticsearch.common.UUIDs#base64UUID()
The following examples show how to use
org.elasticsearch.common.UUIDs#base64UUID() .
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: ElasticsearchTransportFactory.java From database-transform-tool with Apache License 2.0 | 6 votes |
public String bulkUpsert(String index,String type,List<Object> jsons){ try { if(client==null){ init(); } BulkRequestBuilder bulkRequest = client.prepareBulk(); for (Object json : jsons) { JSONObject obj = JSON.parseObject(JSON.toJSONString(json)); String id = UUIDs.base64UUID(); if(obj.containsKey("id")){ id = obj.getString("id"); obj.remove("id"); bulkRequest.add(client.prepareUpdate(index, type, id).setDoc(obj.toJSONString(),XContentType.JSON)); }else{ bulkRequest.add(client.prepareIndex(index, type, id).setSource(obj.toJSONString(),XContentType.JSON)); } } BulkResponse result = bulkRequest.execute().get(); return result.toString(); }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Example 2
Source File: LuceneOrderedDocCollectorTest.java From crate with Apache License 2.0 | 6 votes |
private LuceneOrderedDocCollector collector(IndexSearcher searcher, List<LuceneCollectorExpression<?>> columnReferences, Query query, @Nullable Float minScore, boolean doDocScores) { return new LuceneOrderedDocCollector( new ShardId("dummy", UUIDs.base64UUID(), 0), searcher, query, minScore, doDocScores, 2, RamAccounting.NO_ACCOUNTING, new CollectorContext(), f -> null, new Sort(SortField.FIELD_SCORE), columnReferences, columnReferences ); }
Example 3
Source File: Feature.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Parse raw json content into feature instance. * * @param parser json based content parser * @return feature instance * @throws IOException IOException if content can't be parsed correctly */ public static Feature parse(XContentParser parser) throws IOException { String id = UUIDs.base64UUID(); String name = null; Boolean enabled = null; AggregationBuilder aggregation = null; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); while (parser.nextToken() != XContentParser.Token.END_OBJECT) { String fieldName = parser.currentName(); parser.nextToken(); switch (fieldName) { case FEATURE_ID_FIELD: id = parser.text(); break; case FEATURE_NAME_FIELD: name = parser.text(); break; case FEATURE_ENABLED_FIELD: enabled = parser.booleanValue(); break; case AGGREGATION_QUERY: ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); aggregation = ParseUtils.toAggregationBuilder(parser); break; default: break; } } return new Feature(id, name, enabled, aggregation); }
Example 4
Source File: ElasticsearchHighRestFactory.java From database-transform-tool with Apache License 2.0 | 5 votes |
public String bulkUpsert(String index,String type,List<Object> jsons){ try { if(xclient==null){ init(); } BulkRequest request = new BulkRequest(); for (Object json : jsons) { JSONObject obj = JSON.parseObject(JSON.toJSONString(json)); String id = UUIDs.base64UUID(); if(obj.containsKey("id")){ id = obj.getString("id"); obj.remove("id"); } // if(obj.containsKey("id")){ // request.add(new UpdateRequest(index, type, id).doc(obj.toJSONString(),XContentType.JSON)); // }else{ // request.add(new IndexRequest(index, type).source(obj.toJSONString(),XContentType.JSON)); // } request.add(new UpdateRequest(index, type, id).upsert(obj.toJSONString(),XContentType.JSON)); } BulkResponse result = xclient.bulk(request); return result.toString(); }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Example 5
Source File: ElasticIndexer.java From Stargraph with MIT License | 5 votes |
@Override protected void doIndex(Serializable data, KBId kbId) throws InterruptedException { if (bulkProcessor == null) { throw new StarGraphException("Back-end is unreachable now."); } try { final String id = UUIDs.base64UUID(); IndexRequest request = esClient.createIndexRequest(id, true); this.indexRequests.put(id, request); bulkProcessor.add(request.source(mapper.writeValueAsBytes(data))); } catch (JsonProcessingException e) { throw new IndexingException(e); } }