The BulkProcessor class offers a simple interface to flush bulk operations automatically based on th
来源:互联网 发布:直播讲课哪个软件 编辑:程序博客网 时间:2024/04/27 13:21
1、测试代码
package com.document.api;import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.text.DateFormat;import java.text.ParseException;import java.util.Date;import java.util.Iterator;import java.util.Random;import java.util.Set;import org.elasticsearch.action.bulk.BulkProcessor;import org.elasticsearch.action.bulk.BulkRequest;import org.elasticsearch.action.bulk.BulkRequestBuilder;import org.elasticsearch.action.bulk.BulkResponse;import org.elasticsearch.action.index.IndexRequest;import org.elasticsearch.action.index.IndexResponse;import org.elasticsearch.client.Client;import org.elasticsearch.client.transport.TransportClient;import org.elasticsearch.common.transport.InetSocketTransportAddress;import org.elasticsearch.common.unit.ByteSizeUnit;import org.elasticsearch.common.unit.ByteSizeValue;import org.elasticsearch.common.unit.TimeValue;import com.test.utils.DateUtils;public class Bulk {public static void main(String[] args) throws IOException {@SuppressWarnings("resource")Client client = new TransportClient().addTransportAddresses(new InetSocketTransportAddress("127.0.0.1", 9300));BulkRequestBuilder bulkRequest = client.prepareBulk();BulkProcessor bulkProcessor = BulkProcessor.builder( client, new BulkProcessor.Listener() { @Override public void beforeBulk(long executionId, BulkRequest request) { System.out.println(executionId); } @Override public void afterBulk(long executionId, BulkRequest request, BulkResponse response) { Set<String> set = request.getHeaders(); Iterator<String> iterator = set.iterator(); while(iterator.hasNext()){ String str = iterator.next(); System.out.println(str); } } @Override public void afterBulk(long executionId, BulkRequest request, Throwable failure) { System.out.println("after3"); } }) .setBulkActions(100) //.setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)) .setFlushInterval(TimeValue.timeValueSeconds(5)) .setConcurrentRequests(1) .build();long num = 1;while (num<=1000){bulkProcessor.add(new IndexRequest("mytest", "logs").source(jsonBuilder() .startObject() .field("name", "user"+num) .field("age",new Random().nextInt(20)) .field("grade", new Random().nextInt(3)) .field("description", "i am user"+num) .endObject()));num++;}}}2测试代码
package com.query.dsl;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.Iterator;import java.util.Map;import org.elasticsearch.action.search.SearchResponse;import org.elasticsearch.client.Client;import org.elasticsearch.client.transport.TransportClient;import org.elasticsearch.common.transport.InetSocketTransportAddress;import org.elasticsearch.index.query.BoolQueryBuilder;import org.elasticsearch.index.query.FilterBuilder;import org.elasticsearch.index.query.FilterBuilders;import org.elasticsearch.index.query.QueryBuilders;import org.elasticsearch.search.SearchHit;import org.elasticsearch.search.SearchHits;import org.elasticsearch.search.aggregations.Aggregation;import org.elasticsearch.search.aggregations.AggregationBuilders;import org.elasticsearch.search.aggregations.bucket.filter.Filter;import org.elasticsearch.search.aggregations.bucket.global.Global;import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket;import org.elasticsearch.search.aggregations.metrics.MetricsAggregationBuilder;import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality;import org.elasticsearch.search.aggregations.metrics.percentiles.Percentile;import org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles;import org.elasticsearch.search.aggregations.metrics.sum.Sum;import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount;public class AggregationMatchQuery {public static void main(String[] args) throws ParseException { Client client = new TransportClient().addTransportAddresses(new InetSocketTransportAddress("127.0.0.1", 9300)); SearchResponse sr = client.prepareSearch("mytest") .setTypes("logs") //.setQuery(QueryBuilders.matchPhrasePrefixQuery("name", "user1")) //.setQuery(QueryBuilders.matchPhraseQuery("description", "User6 am i").slop(4)) //.setQuery(QueryBuilders.matchPhrasePrefixQuery("description","i am user2")) .setQuery(QueryBuilders.matchAllQuery()) .setSize(50) .execute() .actionGet(); SearchHits hits = sr.getHits();if (null == hits || hits.totalHits() == 0) {System.out.println("对不起,您没有查询到结果!!");} else {for (SearchHit hit : hits) {String json = hit.getSourceAsString();System.out.println(json);}}}}3、测试结果
log4j:WARN No appenders could be found for logger (org.elasticsearch.plugins).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.{"name":"user1","age":17,"grade":1,"description":"i am user1"}{"name":"user2","age":17,"grade":1,"description":"i am user2"}{"name":"user3","age":15,"grade":2,"description":"i am user3"}{"name":"user4","age":11,"grade":2,"description":"i am user4"}{"name":"user5","age":0,"grade":1,"description":"i am user5"}{"name":"user6","age":5,"grade":2,"description":"i am user6"}{"name":"user7","age":7,"grade":0,"description":"i am user7"}{"name":"user8","age":5,"grade":0,"description":"i am user8"}{"name":"user9","age":3,"grade":1,"description":"i am user9"}{"name":"user10","age":8,"grade":1,"description":"i am user10"}{"name":"user11","age":15,"grade":2,"description":"i am user11"}{"name":"user12","age":15,"grade":0,"description":"i am user12"}{"name":"user13","age":15,"grade":2,"description":"i am user13"}{"name":"user14","age":15,"grade":1,"description":"i am user14"}{"name":"user15","age":14,"grade":1,"description":"i am user15"}{"name":"user16","age":15,"grade":0,"description":"i am user16"}{"name":"user17","age":16,"grade":2,"description":"i am user17"}{"name":"user18","age":5,"grade":0,"description":"i am user18"}{"name":"user19","age":1,"grade":0,"description":"i am user19"}{"name":"user20","age":18,"grade":1,"description":"i am user20"}{"name":"user21","age":17,"grade":2,"description":"i am user21"}{"name":"user22","age":15,"grade":2,"description":"i am user22"}{"name":"user23","age":1,"grade":2,"description":"i am user23"}{"name":"user24","age":10,"grade":0,"description":"i am user24"}{"name":"user25","age":18,"grade":1,"description":"i am user25"}{"name":"user26","age":10,"grade":2,"description":"i am user26"}{"name":"user27","age":9,"grade":2,"description":"i am user27"}{"name":"user28","age":14,"grade":1,"description":"i am user28"}{"name":"user29","age":2,"grade":0,"description":"i am user29"}{"name":"user30","age":10,"grade":0,"description":"i am user30"}{"name":"user31","age":11,"grade":1,"description":"i am user31"}{"name":"user32","age":11,"grade":2,"description":"i am user32"}{"name":"user33","age":6,"grade":1,"description":"i am user33"}{"name":"user34","age":18,"grade":0,"description":"i am user34"}{"name":"user35","age":14,"grade":2,"description":"i am user35"}{"name":"user36","age":17,"grade":0,"description":"i am user36"}{"name":"user37","age":1,"grade":0,"description":"i am user37"}{"name":"user38","age":15,"grade":2,"description":"i am user38"}{"name":"user39","age":5,"grade":0,"description":"i am user39"}{"name":"user40","age":7,"grade":2,"description":"i am user40"}{"name":"user41","age":18,"grade":1,"description":"i am user41"}{"name":"user42","age":12,"grade":1,"description":"i am user42"}{"name":"user43","age":19,"grade":0,"description":"i am user43"}{"name":"user44","age":13,"grade":2,"description":"i am user44"}{"name":"user45","age":1,"grade":2,"description":"i am user45"}{"name":"user46","age":14,"grade":2,"description":"i am user46"}{"name":"user47","age":12,"grade":2,"description":"i am user47"}{"name":"user48","age":5,"grade":1,"description":"i am user48"}{"name":"user49","age":15,"grade":1,"description":"i am user49"}{"name":"user50","age":19,"grade":0,"description":"i am user50"}
0 0
- The BulkProcessor class offers a simple interface to flush bulk operations automatically based on th
- The simple steps on how to create a standby.
- A simple echo client & server based on twisted framework
- Creating a simple web prototype based on CppCMS
- About TortoiseGit TortoiseGit is a Windows Shell Interface to Git and based on TortoiseSVN. It's ope
- A Function to Do All My SQL Statements Based On All The Others Comments
- RevitAPI: Rebar.CreateFromCurves抛出异常: Unable to create a RebarShape based on the given curves
- How to show/hide a control in the Column's DataItemTemplate based on the value of another control
- Simple Sync is a simple sync function-wrapper for node js, based on fibers module.
- Configuring DebugDiag to Automatically Capture a Full User Dump on a Managed Function
- A Reusable Class to Draw a Simple Graph
- a simple GP based C++
- unable to locate a constructor on class ..
- 基于Ffmpeg解码器的简单播放器(a simple audio player based on Ffmpeg)
- CXF A class/interface with the same name 问题
- Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically a
- Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically a
- The design and implementation of a system to detect and filter large sessions automatically
- Volley框架的使用
- 77. Count and Say
- 如何做系列(3)-Java数据类型和MySql数据类型对照表
- iOS开发UI篇:核心动画
- ZooKeeper使用
- The BulkProcessor class offers a simple interface to flush bulk operations automatically based on th
- 开始
- It’s Time to Move to a Four-Tier Application Architecture
- java2 -宏观了解
- 2014年第五届蓝桥杯C/C++程序设计本科B组省赛 切面条(结果填空)
- IOS 小技巧
- C#面向对象编程初步 :字段与属性
- C#学习之ArrayList
- 交叉排序