• ElasticSearch6.0 Java API 使用 排序,分组 ,创建索引,添加索引数据,打分等(一)


    ElasticSearch6.0  Java API  使用     排序,分组 ,创建索引,添加索引数据,打分等

    如果此文章对你有帮助,请关注一下哦

    1.1 搭建maven 工程  创建web工程

      1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      3   <modelVersion>4.0.0</modelVersion>
      4   <groupId>com.elastic</groupId>
      5   <artifactId>search-service</artifactId>
      6   <packaging>war</packaging>
      7   <version>1.0-SNAPSHOT</version>
      8   <name>search-service Maven Webapp</name>
      9   <url>http://maven.apache.org</url>
     10   <properties>
     11     <junit.version>4.5</junit.version>
     12     <spring.version>4.2.4.RELEASE</spring.version>
     13     <mybatis.version>3.2.8</mybatis.version>
     14     <mybatis.spring.version>1.2.2</mybatis.spring.version>
     15     <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
     16     <mysql.version>5.1.32</mysql.version>
     17     <slf4j.version>1.6.4</slf4j.version>
     18     <jackson.version>2.4.2</jackson.version>
     19     <druid.version>1.0.9</druid.version>
     20     <jstl.version>1.2</jstl.version>
     21     <servlet-api.version>2.5</servlet-api.version>
     22     <jsp-api.version>2.0</jsp-api.version>
     23     <joda-time.version>2.5</joda-time.version>
     24     <commons-lang3.version>3.3.2</commons-lang3.version>
     25     <commons-io.version>1.3.2</commons-io.version>
     26     <commons-net.version>3.3</commons-net.version>
     27     <jsqlparser.version>0.9.1</jsqlparser.version>
     28     <commons-fileupload.version>1.3.1</commons-fileupload.version>
     29     <jedis.version>2.7.2</jedis.version>
     30     <activemq.version>5.11.2</activemq.version>
     31     <quartz.version>2.2.2</quartz.version>
     32     <slf4j.version>1.7.21</slf4j.version>
     33     <log4j.version>1.2.12</log4j.version>
     34     <solr.version>6.1.0</solr.version>
     35     <fastjson.version>1.2.13</fastjson.version>
     36     <diamond.version>0.0.1-SNAPSHOT</diamond.version>
     37     <cors.filter>2.5</cors.filter>
     38     <java.property.utils>1.10</java.property.utils>
     39     <jackson.version>2.4.2</jackson.version>
     40   </properties>
     41   <dependencies>
     42     <dependency>
     43       <groupId>junit</groupId>
     44       <artifactId>junit</artifactId>
     45       <version>3.8.1</version>
     46       <scope>test</scope>
     47     </dependency>
     48     <dependency>
     49       <groupId>org.elasticsearch.client</groupId>
     50       <artifactId>transport</artifactId>
     51       <version>6.0.0</version>
     52     </dependency>
     53     <dependency>
     54       <groupId>org.slf4j</groupId>
     55       <artifactId>jcl-over-slf4j</artifactId>
     56       <version>1.7.21</version>
     57       <scope>runtime</scope>
     58     </dependency>
     59     <dependency>
     60       <groupId>org.slf4j</groupId>
     61       <artifactId>slf4j-api</artifactId>
     62       <version>1.7.21</version>
     63     </dependency>
     64     <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
     65     <dependency>
     66       <groupId>org.slf4j</groupId>
     67       <artifactId>slf4j-log4j12</artifactId>
     68       <scope>runtime</scope>
     69     </dependency>
     70     <!-- https://mvnrepository.com/artifact/log4j/log4j -->
     71     <dependency>
     72       <groupId>log4j</groupId>
     73       <artifactId>log4j</artifactId>
     74       <version>1.2.17</version>
     75     </dependency>
     76     <dependency>
     77       <groupId>commons-logging</groupId>
     78       <artifactId>commons-logging</artifactId>
     79       <version>1.2</version>
     80     </dependency>
     81     <dependency>
     82       <groupId>junit</groupId>
     83       <artifactId>junit</artifactId>
     84       <scope>test</scope>
     85     </dependency>
     86     <dependency>
     87       <groupId>javax.servlet</groupId>
     88       <artifactId>servlet-api</artifactId>
     89       <version>2.5</version>
     90       <scope>provided</scope>
     91     </dependency>
     92     <dependency>
     93       <groupId>com.alibaba</groupId>
     94       <artifactId>fastjson</artifactId>
     95     </dependency>
     96     <!-- spring dependencies -->
     97     <dependency>
     98       <groupId>org.springframework</groupId>
     99       <artifactId>spring-core</artifactId>
    100       <version>${spring.version}</version>
    101       <!--<exclusions>-->
    102       <!--<exclusion>-->
    103       <!--<groupId>commons-logging</groupId>-->
    104       <!--<artifactId>commons-logging</artifactId>-->
    105       <!--</exclusion>-->
    106       <!--</exclusions>-->
    107     </dependency>
    108     <dependency>
    109       <groupId>org.springframework</groupId>
    110       <artifactId>spring-test</artifactId>
    111       <version>${spring.version}</version>
    112     </dependency>
    113     <dependency>
    114       <groupId>org.springframework</groupId>
    115       <artifactId>spring-context</artifactId>
    116       <version>${spring.version}</version>
    117     </dependency>
    118     <dependency>
    119       <groupId>org.springframework</groupId>
    120       <artifactId>spring-context-support</artifactId>
    121       <version>${spring.version}</version>
    122     </dependency>
    123     <dependency>
    124       <groupId>org.springframework</groupId>
    125       <artifactId>spring-aop</artifactId>
    126       <version>${spring.version}</version>
    127     </dependency>
    128     <dependency>
    129       <groupId>org.springframework</groupId>
    130       <artifactId>spring-aspects</artifactId>
    131       <version>${spring.version}</version>
    132     </dependency>
    133     <dependency>
    134       <groupId>org.springframework</groupId>
    135       <artifactId>spring-tx</artifactId>
    136       <version>${spring.version}</version>
    137     </dependency>
    138     <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
    139     <dependency>
    140       <groupId>org.springframework</groupId>
    141       <artifactId>spring-jdbc</artifactId>
    142       <version>${spring.version}</version>
    143     </dependency>
    144 
    145     <dependency>
    146       <groupId>org.springframework</groupId>
    147       <artifactId>spring-webmvc</artifactId>
    148       <version>${spring.version}</version>
    149     </dependency>
    150     <!-- mysql dependencies -->
    151     <dependency>
    152       <groupId>mysql</groupId>
    153       <artifactId>mysql-connector-java</artifactId>
    154       <version>5.1.32</version>
    155     </dependency>
    156     <!-- https://mvnrepository.com/artifact/com.thetransactioncompany/cors-filter -->
    157     <dependency>
    158       <groupId>com.thetransactioncompany</groupId>
    159       <artifactId>cors-filter</artifactId>
    160       <version>${cors.filter}</version>
    161     </dependency>
    162     <!-- https://mvnrepository.com/artifact/com.thetransactioncompany/java-property-utils -->
    163     <dependency>
    164       <groupId>com.thetransactioncompany</groupId>
    165       <artifactId>java-property-utils</artifactId>
    166       <version>${java.property.utils}</version>
    167 
    168     </dependency>
    169     <dependency>
    170       <groupId>com.alibaba</groupId>
    171       <artifactId>fastjson</artifactId>
    172       <version>${fastjson.version}</version>
    173     </dependency>
    174   </dependencies>
    175   <build>
    176     <finalName>search-service</finalName>
    177   </build>
    178 </project>

    1.2 创建web项目

    2.1  编写Java  elasticsearch 客户端连接公共类  (这里使用elasticsearch单机版)

     1 package com.elastic.common.conn;
     2 
     3 import org.elasticsearch.client.transport.TransportClient;
     4 import org.elasticsearch.common.settings.Settings;
     5 import org.elasticsearch.common.transport.TransportAddress;
     6 import org.elasticsearch.transport.client.PreBuiltTransportClient;
     7 import org.springframework.stereotype.Component;
     8 
     9 import java.net.InetAddress;
    10 
    11 /**
    12  * Created by xiaotian on 2017/12/1.
    13  */
    14 @Component
    15 public class EsClient {
    16 
    17     //private  EsClient client = new EsClient();
    18     TransportClient client = null;
    19     public  EsClient(){
    20         try{
    21             Settings settings = Settings.builder()
    22                     .put("client.transport.sniff", true)
    23                     .put("cluster.name", "elasticsearch").build();
    24             client = new PreBuiltTransportClient(Settings.EMPTY)
    25                     .addTransportAddress(new TransportAddress(InetAddress.getByName("eshost"), 9300));
    26 
    27         }catch (Exception ex){
    28             client.close();
    29         }finally {
    30 
    31         }
    32     }
    33     public  TransportClient getConnection(){
    34 
    35            if (client==null){
    36                synchronized (EsClient.class){
    37                    if (client==null){
    38                        new EsClient();
    39                    }
    40                }
    41            }
    42            return  client;
    43 
    44     }
    45 
    46 }

     2.2  service层  接口设计 

    1. IndexService
     1 package com.elastic.service.inter;
     2 
     3 /**
     4  * Created by xiaotian on 2017/12/1.
     5  */
     6 public interface IndexService {
     7 
     8    public void  index(String id);
     9 
    10    public  void  get();
    11    public  void  del(String id);
    12    public  void  update(String id) throws  Exception;
    13    public  void  multiGet(String ... ids) throws  Exception;
    14    public  void  bulk(String ... ids) throws  Exception;
    15    public  void  bulkProcesstor(String index,String type,String... ids) throws  Exception;
    16 
    17 }
    2. SearchService

     1 package com.elastic.service.inter;
     2 
     3 /**
     4  * Created by xiaotian on 2017/12/2.
     5  */
     6 public interface SearchService {
     7     public void  search();
     8     public void  searchByCondition() throws Exception;
     9     public void  multiSearch();
    10     public void aggsearch();
    11     public void metricsAgg();
    12 
    13 }

    3. service层 接口实现 

      IndexServiceImpl 

      1 package com.elastic.service.impl;
      2 
      3 import com.alibaba.fastjson.JSONObject;
      4 import com.elastic.common.conn.EsClient;
      5 import com.elastic.service.inter.IndexService;
      6 import org.elasticsearch.action.ActionListener;
      7 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
      8 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
      9 import org.elasticsearch.action.bulk.*;
     10 import org.elasticsearch.action.get.GetResponse;
     11 import org.elasticsearch.action.get.MultiGetItemResponse;
     12 import org.elasticsearch.action.get.MultiGetResponse;
     13 import org.elasticsearch.action.index.IndexRequest;
     14 import org.elasticsearch.action.index.IndexRequestBuilder;
     15 import org.elasticsearch.action.index.IndexResponse;
     16 import org.elasticsearch.client.Requests;
     17 import org.elasticsearch.common.document.DocumentField;
     18 import org.elasticsearch.common.unit.ByteSizeUnit;
     19 import org.elasticsearch.common.unit.ByteSizeValue;
     20 import org.elasticsearch.common.unit.TimeValue;
     21 import org.elasticsearch.common.xcontent.XContentBuilder;
     22 import org.elasticsearch.common.xcontent.XContentType;
     23 import org.elasticsearch.index.query.QueryBuilders;
     24 import org.elasticsearch.index.reindex.BulkByScrollResponse;
     25 import org.elasticsearch.index.reindex.DeleteByQueryAction;
     26 import org.elasticsearch.rest.RestStatus;
     27 import org.springframework.beans.factory.annotation.Autowired;
     28 import org.springframework.stereotype.Service;
     29 
     30 import java.io.IOException;
     31 import java.util.*;
     32 
     33 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
     34 
     35 /**
     36  * Created by xiaotian on 2017/12/1.
     37  */
     38 @Service
     39 public class IndexServiceImpl implements IndexService {
     40 
     41     @Autowired
     42     private EsClient client;
     43 
     44     public void index(String id) {
     45 //        String json = "{" +
     46 //                ""user":"kimchy"," +
     47 //                ""postDate":"2013-01-30"," +
     48 //                ""message":"trying out Elasticsearch"" +
     49 //                "}";
     50         try {
     51 
     52 
     53         Map<String, Object> jsonMap = new HashMap<String, Object>();
     54         jsonMap.put("name","jim"+id);
     55         jsonMap.put("age",20+id);
     56         jsonMap.put("date",new Date());
     57         jsonMap.put("message","测试"+id);
     58         jsonMap.put("tel","1234567");
     59         //IndexResponse indexResponse = client.getConnection().prepareIndex("twitter", "tweet").setSource(JSONObject.toJSON(jsonMap), XContentType.JSON).get();
     60         IndexResponse indexResponse = client.getConnection().prepareIndex("xiaot", "test",id).setSource(jsonMap).get();
     61        // Index name
     62         String _index = indexResponse.getIndex();
     63         // Type name
     64         String _type = indexResponse.getType();
     65         // Document ID (generated or not)
     66         String _id = indexResponse.getId();
     67         // Version (if it's the first time you index this document, you will get: 1)
     68         long _version = indexResponse.getVersion();
     69         // status has stored current instance statement.
     70         RestStatus status = indexResponse.status();
     71         System.out.println(_index+"_"+_type+"_"+_id+"_"+_version+"_"+status);
     72         }catch (Exception ex){
     73             ex.printStackTrace();
     74         }
     75 
     76     }
     77 
     78     public void get() {
     79         GetResponse response = client.getConnection().prepareGet("twitter", "tweet", "94pKEWABJOgzR6sJVCCV").get();
     80         Map<String, DocumentField> fields = response.getFields();
     81         System.out.println("map:"+fields);
     82         String index = response.getIndex();
     83         Map<String, Object> source = response.getSource();
     84         String id = response.getId();
     85         System.out.println(source);
     86 
     87     }
     88 
     89     public void del(String id) {
     90         DeleteByQueryAction.INSTANCE.newRequestBuilder(client.getConnection())
     91                 .filter(QueryBuilders.matchQuery("_id",id))
     92                 .source("twitter")
     93                 .execute(new ActionListener<BulkByScrollResponse>() {
     94                     public void onResponse(BulkByScrollResponse response) {
     95                         long deleted = response.getDeleted();
     96                         System.out.println("delete"+deleted);
     97                     }
     98 
     99                     public void onFailure(Exception e) {
    100 
    101                     }
    102                 });
    103     }
    104 
    105     public void update(String id)  throws  Exception{
    106         client.getConnection().prepareUpdate("twitter","tweet",id)
    107                 .setDoc(jsonBuilder()
    108                         .startObject()
    109                         .field("name", "tom")
    110                         .endObject()).get();
    111     }
    112 
    113     public void multiGet(String... ids) throws Exception {
    114         MultiGetResponse multiGetResponse = client.getConnection().prepareMultiGet()
    115                 .add("twitter", "tweet", ids[0])
    116                 .add("twitter", "tweet", ids[1], ids[2], ids[3])
    117                 .get();
    118         for (MultiGetItemResponse multiGetItemResponse : multiGetResponse) {
    119             GetResponse response = multiGetItemResponse.getResponse();
    120             if (response.isExists()){
    121                 System.out.println(response.getSourceAsString());
    122             }
    123         }
    124     }
    125 
    126     public void bulk(String... ids) throws Exception {
    127         BulkRequestBuilder prepareBulk = client.getConnection().prepareBulk();
    128         for (String id : ids) {
    129             prepareBulk.add(client.getConnection().prepareIndex("twitter","tweet",id)
    130             .setSource(jsonBuilder().startObject().field("name","肖添"+id).endObject()));
    131 
    132         }
    133         BulkResponse responses = prepareBulk.get();
    134         System.out.println(responses.hasFailures());
    135         for (BulkItemResponse response : responses) {
    136             System.out.println(response.getResponse().getId() + "," + response.getResponse().getIndex() + "," + response.getResponse().getResult());
    137         }
    138 
    139     }
    140 
    141     public void bulkProcesstor(String index,String type,String... ids) throws Exception {
    142         try {
    143 
    144            //IndexResponse indexResponse = client.getConnection().prepareIndex(index, type).setSource(getMapping()).get();
    145            IndexResponse indexResponse = client.getConnection().prepareIndex(index, type).setSource().get();
    146 
    147             PutMappingRequest mappingRequest = Requests.putMappingRequest(index).type(type).source(getMapping());
    148             PutMappingResponse putMappingResponse = client.getConnection().admin().indices().putMapping(mappingRequest).actionGet();
    149             //client.getConnection().prepareIndex("temp1","test").
    150             BulkProcessor bulkProcessor = BulkProcessor.builder(client.getConnection(), new BulkProcessor.Listener() {
    151                 public void beforeBulk(long executionId, BulkRequest bulkRequest) {
    152                     System.out.println("beforeBulk:" + executionId + "," + bulkRequest.getDescription() + "," + bulkRequest.numberOfActions());
    153                 }
    154 
    155                 public void afterBulk(long executionId, BulkRequest bulkRequest, BulkResponse bulkResponse) {
    156                     System.out.println("afterBulk:" + executionId + "," + bulkRequest.getDescription() + "," + bulkRequest.numberOfActions());
    157                     System.out.println("afterBulk:" + executionId + "," + bulkResponse.getItems() + "," + bulkResponse.getTook());
    158                 }
    159 
    160                 public void afterBulk(long executionId, BulkRequest bulkRequest, Throwable throwable) {
    161                     System.out.println("afterBulk:" + executionId + "," + bulkRequest.getParentTask() + "," + bulkRequest.getDescription() + "," + throwable);
    162                 }
    163             })
    164                     .setBulkActions(10)
    165                     .setBulkSize(new ByteSizeValue(5, ByteSizeUnit.MB))
    166                     .setConcurrentRequests(1)
    167                     .setFlushInterval(TimeValue.timeValueMillis(1))
    168                     .setBackoffPolicy(BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(100), 3)).build();
    169 
    170             for (String id : ids) {
    171                 Map<String, Object> jsonMap = new HashMap<String, Object>();
    172                 jsonMap.put("name","中华人民共和国"+id);
    173                 jsonMap.put("age",30+Integer.parseInt(id));
    174                 jsonMap.put("date",new Date());
    175                 jsonMap.put("message","程序设计"+id);
    176                 jsonMap.put("tel","18612855433");
    177                 jsonMap.put("attr_name",new String[]{"品牌_sku_attr"+id,"商品类别_sku_attr"+id,"面料_sku_attr"+id});
    178                 jsonMap.put("create_date",new Date());
    179                 bulkProcessor.add(new IndexRequest(index,type,id).source(jsonMap));
    180 
    181             }
    182             bulkProcessor.close();
    183         } catch (Exception e) {
    184             e.printStackTrace();
    185             System.out.println(e);
    186         }finally {
    187 
    188         }
    189 
    190     }
    191 
    192     private XContentBuilder getMapping() throws Exception{
    193         XContentBuilder mapping = null;
    194         try {
    195 
    196             mapping = jsonBuilder().startObject()//.startObject("_ttl").field("enabled",false).endObject()
    197                                                    .startObject("properties").startObject("name").field("type","text").field("analyzer","ik_max_word")
    198                                                    .field("search_analyzer","ik_max_word").endObject()
    199                                                    .startObject("age").field("type","long").endObject()
    200                                                    .startObject("date").field("type","date").endObject()
    201                                                     .startObject("message").field("type","keyword").field("index","true").endObject()
    202                                                     .startObject("tel").field("type","keyword").endObject()
    203                                                     .startObject("attr_name").field("type","keyword").field("index","true").endObject()
    204                          .endObject()
    205                     .endObject();
    206         } catch (IOException e) {
    207             e.printStackTrace();
    208         }
    209 
    210        return  mapping;
    211     }
    212 }

    SearchServiceImpl

      1 package com.elastic.service.impl;
      2 
      3 import com.elastic.common.conn.EsClient;
      4 import com.elastic.service.inter.SearchService;
      5 import org.apache.lucene.index.Term;
      6 import org.elasticsearch.action.search.MultiSearchResponse;
      7 import org.elasticsearch.action.search.SearchRequestBuilder;
      8 import org.elasticsearch.action.search.SearchResponse;
      9 import org.elasticsearch.action.search.SearchType;
     10 import org.elasticsearch.common.lucene.search.function.CombineFunction;
     11 import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
     12 import org.elasticsearch.index.query.*;
     13 import org.elasticsearch.index.query.functionscore.*;
     14 import org.elasticsearch.join.aggregations.Children;
     15 import org.elasticsearch.script.Script;
     16 import org.elasticsearch.script.ScriptService;
     17 import org.elasticsearch.script.ScriptType;
     18 import org.elasticsearch.search.SearchHit;
     19 import org.elasticsearch.search.SearchHits;
     20 import org.elasticsearch.search.aggregations.*;
     21 import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
     22 import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregator;
     23 import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
     24 import org.elasticsearch.search.aggregations.bucket.range.Range;
     25 import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
     26 import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator;
     27 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
     28 import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
     29 import org.elasticsearch.search.aggregations.metrics.avg.Avg;
     30 import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder;
     31 import org.elasticsearch.search.aggregations.metrics.max.Max;
     32 import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder;
     33 import org.elasticsearch.search.aggregations.metrics.min.Min;
     34 import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder;
     35 import org.elasticsearch.search.aggregations.metrics.stats.Stats;
     36 import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder;
     37 import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats;
     38 import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder;
     39 import org.elasticsearch.search.aggregations.metrics.sum.Sum;
     40 import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder;
     41 import org.elasticsearch.search.rescore.RescoreBuilder;
     42 import org.elasticsearch.search.sort.SortOrder;
     43 import org.slf4j.Logger;
     44 import org.springframework.beans.factory.annotation.Autowired;
     45 import org.springframework.stereotype.Service;
     46 
     47 import java.text.SimpleDateFormat;
     48 import java.util.HashMap;
     49 import java.util.List;
     50 import java.util.Map;
     51 
     52 import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
     53 
     54 /**
     55  * Created by xiaotian on 2017/12/2.
     56  */
     57 @Service
     58 public class SearchServiceImpl implements SearchService {
     59     @Autowired
     60     private EsClient client;
     61 
     62     private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SearchServiceImpl.class);
     63 
     64     public void search() {
     65         SearchResponse searchResponse = client.getConnection().prepareSearch("twitter")
     66                 .setTypes("tweet")
     67                 .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
     68                 .setQuery(QueryBuilders.matchQuery("name","三胖子"))
     69                 .setPostFilter(QueryBuilders.rangeQuery("age").from(19).to(400))
     70                 .setFrom(0).setSize(20).setExplain(true)
     71                 //.addAggregation(AggregationBuilder.CommonFields.FIELD.match(""))
     72                 .get();
     73 
     74         SearchHits hits = searchResponse.getHits();
     75         for (SearchHit hit : hits) {
     76             System.out.println(hit.getSourceAsMap());
     77         }
     78     }
     79 
     80     public void searchByCondition()  throws Exception{
     81 
     82 
     83         SearchRequestBuilder searchRequestBuilder = client.getConnection().prepareSearch("red89")
     84                 .setTypes("test");
     85 
     86 
     87         Map<String, Object> params = new HashMap<>();
     88         params.put("num1", 1);
     89         params.put("num2", 2);
     90 
     91         String inlineScript = "long age;if (doc['age'].value < 45)  age = doc['age'].value + 50; return age * params.num1;";
     92                // + "return (diff +num1+num2)";
     93         Script script = new Script(ScriptType.INLINE,"painless",inlineScript , params);
     94         ScriptScoreFunctionBuilder scriptScoreFunctionBuilder = ScoreFunctionBuilders.scriptFunction(script);
     95 
     96 
     97 
     98         //MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("name", "中华");
     99 
    100         searchRequestBuilder.setQuery(functionScoreQuery(QueryBuilders.matchQuery("name","中华").operator(Operator.AND),scriptScoreFunctionBuilder));
    101        // searchRequestBuilder.setQuery(QueryBuilders.matchQuery("name","中华").operator(Operator.AND));
    102         BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    103         BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
    104         getFilterQuery("tel",new String[]{"18612855433"},"AND",queryBuilder);
    105        // getFilterQuery("name",new String[]{"中华人民共和国"},"AND",queryBuilder);
    106 
    107 
    108         //getFilterQuery("age",new String[]{"40"},"AND",queryBuilder);
    109         //getFilterQuery("message",new String[]{"程序设计19"},"AND",queryBuilder);
    110         boolQueryBuilder.must(queryBuilder);
    111         //boolQueryBuilder.must();
    112        // boolQueryBuilder.must(getRangeFilterQuery("age",new Integer[]{null,45}));
    113         //new_score = old_score * log(1 + factor * number_of_votes)
    114 
    115        FieldValueFactorFunctionBuilder age = ScoreFunctionBuilders.fieldValueFactorFunction("age").modifier(FieldValueFactorFunction.Modifier.LN1P).factor(10);
    116         FieldValueFactorFunctionBuilder age1 = ScoreFunctionBuilders.fieldValueFactorFunction("age").modifier(FieldValueFactorFunction.Modifier.LN1P).factor(4);
    117         FunctionScoreQueryBuilder.FilterFunctionBuilder[] filterFunctionBuilders =
    118                 new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{new FunctionScoreQueryBuilder.FilterFunctionBuilder(age),new FunctionScoreQueryBuilder.FilterFunctionBuilder(age1)};
    119         //FunctionScoreQueryBuilder scoreQueryBuilder = functionScoreQuery(boolQueryBuilder, filterFunctionBuilders).boostMode(CombineFunction.SUM);
    120 
    121        // FunctionScoreQueryBuilder functionScoreQueryBuilder = functionScoreQuery(boolQueryBuilder, scriptScoreFunctionBuilder);
    122         searchRequestBuilder.setPostFilter(boolQueryBuilder);
    123         searchRequestBuilder.setFrom(0);
    124         searchRequestBuilder.setSize(20);
    125         searchRequestBuilder.setExplain(true);
    126 
    127         TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("agg").field("attr_name");//.subAggregation(AggregationBuilders.topHits("top").from(0).size(10)).size(100);
    128         RangeAggregationBuilder rangeAggregationBuilder = AggregationBuilders.range("range").field("age").addRange(0, 30).addRange(30,50).addRange(50,100);
    129 
    130         aggregationBuilder.size(100);
    131 
    132         AggregationBuilder filter = AggregationBuilders.filter("agg", boolQueryBuilder)
    133                 .subAggregation(aggregationBuilder);
    134 
    135         searchRequestBuilder.addAggregation(filter);
    136         searchRequestBuilder.addAggregation(rangeAggregationBuilder);
    137        // searchRequestBuilder.addAggregation(filter);
    138         //searchRequestBuilder.addSort("age",SortOrder.DESC);
    139 
    140 
    141 
    142 
    143 
    144         //打分
    145         //searchRequestBuilder.addRescorer(RescoreBuilder.queryRescorer(QueryBuilders.functionScoreQuery(ScoreFunctionBuilders.fieldValueFactorFunction("age"))));
    146 
    147         SearchResponse searchResponse1 = searchRequestBuilder.get();
    148 
    149 
    150         System.out.println("param:"+searchRequestBuilder.toString());
    151 
    152 
    153 
    154         System.out.println("aaaa"+searchResponse1.getAggregations().getAsMap());
    155 
    156 
    157         InternalFilter aggFilter = searchResponse1.getAggregations().get("agg");
    158         System.out.println(aggFilter.toString());
    159         Terms agg = aggFilter.getAggregations().get("agg");
    160 
    161         agg.getBuckets().forEach(bucket ->{
    162             System.out.println(bucket.getKey()+":"+bucket.getDocCount());
    163         } );
    164         System.out.println("--------------------------------");
    165         Range range = searchResponse1.getAggregations().get("range");
    166 
    167         range.getBuckets().forEach(bucket ->{
    168             //System.out.println(bucket.getKey()+":"+bucket.getDocCount());
    169             //logger.info("key [{}], from [{}], to [{}], doc_count [{}]", bucket.getKey(), bucket.getFrom(),bucket.getTo(),bucket.getDocCount());
    170             System.out.println(String.format("key [%s], from [%s], to [%s], doc_count [%d]", bucket.getKey(), bucket.getFrom(),bucket.getTo(),bucket.getDocCount()));
    171 
    172     });
    173 
    174         SearchHits hits = searchResponse1.getHits();
    175         for (SearchHit hit : hits) {
    176             System.out.println(hit.getSourceAsMap());
    177         }
    178 
    179         System.out.println("---------------------");
    180 
    181 //
    182 //        SearchRequestBuilder searchRequestBuilder1 = client.getConnection().prepareSearch("red88")
    183 //                .setTypes("test");
    184 ////        QueryBuilder tel = QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("tel","18612855433")).should(QueryBuilders.matchQuery("message","程序设计"));
    185 ////        BoolQueryBuilder filter1 = QueryBuilders.boolQuery()//.must(QueryBuilders.matchQuery("age", "40").operator(Operator.AND))
    186 ////                .must(QueryBuilders.rangeQuery("age").from(0).to(40))
    187 ////                .must(tel);
    188 //        searchRequestBuilder.setQuery(QueryBuilders.matchQuery("name","三胖子").operator(Operator.AND));
    189 //        BoolQueryBuilder boolQueryBuilder1 = QueryBuilders.boolQuery();
    190 //        BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery();
    191 //        getFilterQuery("tel",new String[]{"18612855433"},"OR",queryBuilder1);
    192 //        getFilterQuery("message",new String[]{"程序设计"},"OR",queryBuilder1);
    193 //        boolQueryBuilder.must(queryBuilder);
    194 //        //boolQueryBuilder.must();
    195 //        boolQueryBuilder.must(getRangeFilterQuery("age",new Integer[]{null,40}));
    196 //        searchRequestBuilder.setPostFilter(boolQueryBuilder1);
    197 //        searchRequestBuilder.setFrom(0);
    198 //        searchRequestBuilder.setSize(20);
    199 //        searchRequestBuilder.setExplain(true);
    200 //        TermsAggregationBuilder aggregationBuilder1 = AggregationBuilders.terms("agg").field("attr_name");
    201 //
    202 //        aggregationBuilder.size(100);
    203 //        searchRequestBuilder.addAggregation(aggregationBuilder);
    204 //        searchRequestBuilder.addSort("age",SortOrder.DESC);
    205 //
    206 
    207 
    208 
    209 
    210     }
    211 
    212     public FunctionScoreQueryBuilder sortByFucntion(QueryBuilder queryBuilder) {
    213         FunctionScoreQueryBuilder query = functionScoreQuery(queryBuilder,
    214                 ScoreFunctionBuilders.fieldValueFactorFunction("age").modifier(FieldValueFactorFunction.Modifier.LN1P).factor(1f)).boostMode(CombineFunction.SUM);
    215         //.add(ScoreFunctionBuilders.fieldValueFactorFunction(查询字段).modifier(Modifier.RECIPROCAL).factor(1)).boostMode(“sum”);
    216         return query;
    217     }
    218     private QueryBuilder getFilterQuery(String fieldName, Object[] fieldValues,String andor,BoolQueryBuilder queryBuilder) {
    219         //BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    220 
    221         for (int i = 0; i < fieldValues.length; i++) {
    222             if ("OR".equals(andor)){
    223                 queryBuilder.should(QueryBuilders.matchQuery(fieldName,fieldValues[i]).operator(Operator.OR));
    224             }else if ("AND".equals(andor)){
    225                 queryBuilder.must(QueryBuilders.matchQuery(fieldName,fieldValues[i]).operator(Operator.AND));
    226             }
    227         }
    228 
    229         return  queryBuilder;
    230 
    231     }
    232     private QueryBuilder getFilterQuery(String fieldName, Object[] fieldValues,String andor) {
    233         BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    234 
    235         for (int i = 0; i < fieldValues.length; i++) {
    236             if ("OR".equals(andor)){
    237                 boolQueryBuilder.should(QueryBuilders.matchQuery(fieldName,fieldValues[i]));
    238             }else if ("AND".equals(andor)){
    239              boolQueryBuilder.must(QueryBuilders.matchQuery(fieldName,fieldValues[i]));
    240             }
    241         }
    242 
    243         return  boolQueryBuilder;
    244 
    245     }
    246 
    247     private RangeQueryBuilder getRangeFilterQuery(String fieldName, Integer[] values) {
    248         RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(fieldName);
    249         rangeQueryBuilder.from(values[0]==null?0:values[0]);
    250         rangeQueryBuilder.to((values.length<2||values[1]==null)?99999999:values[1]);
    251         return rangeQueryBuilder;
    252     }
    253 
    254 
    255     public void multiSearch() {
    256 
    257         SearchRequestBuilder srb1 = client.getConnection().prepareSearch().setQuery(QueryBuilders.matchQuery("name", "tom")).setSize(1);
    258         SearchRequestBuilder srb2 = client.getConnection().prepareSearch().setQuery(QueryBuilders.matchQuery("name", "三胖子")).setSize(1);
    259         MultiSearchResponse multiSearchResponse = client.getConnection().prepareMultiSearch()
    260                 .add(srb1)
    261                 .add(srb2)
    262                 .get();
    263 
    264         for (MultiSearchResponse.Item item : multiSearchResponse.getResponses()) {
    265             for (SearchHit hit : item.getResponse().getHits().getHits()) {
    266                 System.out.println(hit.getSourceAsMap());
    267 
    268             }
    269         }
    270 
    271     }
    272 
    273     public void aggsearch() {
    274         SearchRequestBuilder requestBuilder = client.getConnection().prepareSearch("twitter").setTypes("tweet")
    275                 .setFrom(0).setSize(100);
    276         AggregationBuilder aggregationBuilder = AggregationBuilders.terms("agg").field("name").subAggregation(AggregationBuilders.terms("add").field("age"));
    277         SearchResponse response = requestBuilder.setQuery(QueryBuilders.matchQuery("name", "三胖"))
    278                 .addAggregation(aggregationBuilder)
    279                 .addSort("age", SortOrder.DESC)
    280                 .setExplain(true).execute().actionGet();
    281         SearchHits searchHits = response.getHits();
    282 
    283         Terms agg = response.getAggregations().get("agg");
    284         Children children = response.getAggregations().get("agg");
    285         System.out.println(agg.getBuckets());
    286         for (Terms.Bucket bucket : agg.getBuckets()) {
    287             System.out.println(bucket.getKey() + ":" + bucket.getDocCount());
    288         }
    289         System.out.println(children.getAggregations().getAsMap());
    290 
    291     }
    292 
    293     public void metricsAgg() {
    294 
    295         SearchRequestBuilder searchRequestBuilder = client.getConnection().prepareSearch("hello").setTypes("test").setFrom(0).setSize(100);
    296         MinAggregationBuilder minAggregationBuilder = AggregationBuilders.min("agg").field("age");
    297         SearchResponse response = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery())
    298                 .addAggregation(minAggregationBuilder).setExplain(true).execute().actionGet();
    299         Min min = response.getAggregations().get("agg");
    300         System.out.println("min:"+min.getValue());
    301         MaxAggregationBuilder maxAggregationBuilder = AggregationBuilders.max("max_age").field("age");
    302         SearchResponse response1 = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery())
    303                 .addAggregation(maxAggregationBuilder).setExplain(true).execute().actionGet();
    304         Max max_age = response1.getAggregations().get("max_age");
    305         System.out.println("max:"+max_age.getValue());
    306 
    307         AvgAggregationBuilder avgAggregationBuilder = AggregationBuilders.avg("avg_age").field("age");
    308         SearchResponse response2 = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery())
    309                 .addAggregation(avgAggregationBuilder).setExplain(true).execute().actionGet();
    310         Avg avg_age = response2.getAggregations().get("avg_age");
    311         System.out.println("avg_age:"+avg_age.getValue());
    312 
    313         SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum("sum_age").field("age");
    314         SearchResponse searchResponse = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery()).addAggregation(sumAggregationBuilder)
    315                 .setExplain(true).execute().actionGet();
    316         Sum sum_age = searchResponse.getAggregations().get("sum_age");
    317         System.out.println("sum_age:"+sum_age.getValue());
    318 
    319         System.out.println("---------------------------");
    320 
    321         StatsAggregationBuilder statsAggregationBuilder = AggregationBuilders.stats("agg_status").field("age");
    322         SearchResponse searchResponse1 = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery()).addAggregation(statsAggregationBuilder)
    323                 .setExplain(true).execute().actionGet();
    324 
    325         Stats agg_status = searchResponse1.getAggregations().get("agg_status");
    326         double min1 = agg_status.getMin();
    327         double max = agg_status.getMax();
    328         long count = agg_status.getCount();
    329         double sum = agg_status.getSum();
    330         double avg = agg_status.getAvg();
    331         System.out.println("---------------------------------");
    332         System.out.println("min1="+min1);
    333         System.out.println("max="+max);
    334         System.out.println("count="+count);
    335         System.out.println("sum="+sum);
    336         System.out.println("avg="+avg);
    337 
    338         ExtendedStatsAggregationBuilder extendedStatsAggregationBuilder = AggregationBuilders.extendedStats("extend_status").field("age");
    339 
    340         SearchResponse searchResponse2 = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery()).addAggregation(extendedStatsAggregationBuilder).setExplain(true).execute().actionGet();
    341         ExtendedStats extend_status = searchResponse2.getAggregations().get("extend_status");
    342         double extend_min = extend_status.getMin();
    343         double extend_max = extend_status.getMax();
    344         long extend_count = extend_status.getCount();
    345         double extend_sum = extend_status.getSum();
    346         double extend_avg = extend_status.getAvg();
    347         System.out.println("---------------------------------");
    348         System.out.println("extend_min="+extend_min);
    349         System.out.println("extend_max="+extend_max);
    350         System.out.println("extend_count="+extend_count);
    351         System.out.println("extend_sum="+extend_sum);
    352         System.out.println("extend_avg="+extend_avg);
    353 
    354 
    355     }
    356 }

    3.1 controller层实现

    IndexController
     1 package com.elastic.controller;
     2 
     3 import com.elastic.service.inter.IndexService;
     4 import org.springframework.beans.factory.annotation.Autowired;
     5 import org.springframework.stereotype.Controller;
     6 import org.springframework.web.bind.annotation.RequestMapping;
     7 
     8 import javax.servlet.http.HttpServletRequest;
     9 import javax.servlet.http.HttpServletResponse;
    10 import java.io.IOException;
    11 
    12 /**
    13  * Created by xiaotian on 2017/12/1.
    14  */
    15 @Controller
    16 public class IndexController {
    17 
    18     @Autowired
    19     private IndexService indexService;
    20 
    21     @RequestMapping("/index")
    22     public  void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
    23 
    24         indexService.index(request.getParameter("id"));
    25     }
    26     @RequestMapping("/get")
    27     public  void get(){
    28 
    29         indexService.get();
    30     }
    31 
    32     @RequestMapping("/del")
    33     public  void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    34 
    35         indexService.del(request.getParameter("id"));
    36     }
    37     @RequestMapping("/update")
    38     public  void update(HttpServletRequest request, HttpServletResponse response) throws Exception {
    39 
    40         indexService.update(request.getParameter("id"));
    41     }
    42     @RequestMapping("/multiGet")
    43     public  void multiGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
    44 
    45         indexService.multiGet(request.getParameter("id").split(","));
    46     }
    47     @RequestMapping("/bulk")
    48     public  void bulk(HttpServletRequest request, HttpServletResponse response) throws Exception {
    49 
    50         indexService.bulk(request.getParameter("id").split(","));
    51     }
    52     @RequestMapping("/bulkP")
    53     public  void bulkProcesstor(HttpServletRequest request, HttpServletResponse response) throws Exception {
    54         String index = request.getParameter("index");
    55         String type = request.getParameter("type");
    56         String[] ids = request.getParameter("id").split(",");
    57         indexService.bulkProcesstor(index,type,ids);
    58     }
    59 }
    SearchController
     1 package com.elastic.controller;
     2 
     3 import com.elastic.service.inter.SearchService;
     4 import org.springframework.beans.factory.annotation.Autowired;
     5 import org.springframework.stereotype.Controller;
     6 import org.springframework.web.bind.annotation.RequestMapping;
     7 
     8 import javax.servlet.http.HttpServletRequest;
     9 import javax.servlet.http.HttpServletResponse;
    10 import java.io.IOException;
    11 
    12 /**
    13  * Created by xiaotian on 2017/12/2.
    14  */
    15 @Controller
    16 public class SearchController {
    17 
    18     @Autowired
    19     private SearchService searchService;
    20     @RequestMapping("/search")
    21     public  void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
    22 
    23         searchService.search();
    24     }
    25     @RequestMapping("/multiSearch")
    26     public  void multiSearch(HttpServletRequest request, HttpServletResponse response) throws IOException {
    27 
    28         searchService.multiSearch();
    29     }
    30     @RequestMapping("/aggsearch")
    31     public  void aggsearch(HttpServletRequest request, HttpServletResponse response) throws IOException {
    32 
    33         searchService.aggsearch();
    34     }
    35 
    36     @RequestMapping("/metricsAgg")
    37     public  void metricsAgg(HttpServletRequest request, HttpServletResponse response) throws IOException {
    38 
    39         searchService.metricsAgg();
    40     }
    41     @RequestMapping("/searchFilter")
    42     public  void searchByCondition(HttpServletRequest request, HttpServletResponse response) throws Exception {
    43 
    44         searchService.searchByCondition();
    45     }
    46 }

    4. 通过kibana进行索引建立和查询等

      1 GET red89/test/_search
      2 
      3 {
      4   "from" : 0,
      5   "size" : 20,
      6   "query" : {
      7     "match" : {
      8       "name" : {
      9         "query" : "中华",
     10         "operator" : "AND",
     11         "prefix_length" : 0,
     12         "max_expansions" : 50,
     13         "fuzzy_transpositions" : true,
     14         "lenient" : false,
     15         "zero_terms_query" : "NONE",
     16         "boost" : 1.0
     17       }
     18     }
     19   },
     20   "post_filter" : {
     21     "bool" : {
     22       "must" : [
     23         {
     24           "bool" : {
     25             "should" : [
     26               {
     27                 "match" : {
     28                   "tel" : {
     29                     "query" : "18612855433",
     30                     "operator" : "OR",
     31                     "prefix_length" : 0,
     32                     "max_expansions" : 50,
     33                     "fuzzy_transpositions" : true,
     34                     "lenient" : false,
     35                     "zero_terms_query" : "NONE",
     36                     "boost" : 1.0
     37                   }
     38                 }
     39               }
     40             ],
     41             "adjust_pure_negative" : true,
     42             "boost" : 1.0
     43           }
     44         },
     45         {
     46           "range" : {
     47             "age" : {
     48               "from" : 0,
     49               "to" : 45,
     50               "include_lower" : true,
     51               "include_upper" : true,
     52               "boost" : 1.0
     53             }
     54           }
     55         }
     56       ],
     57       "adjust_pure_negative" : true,
     58       "boost" : 1.0
     59     }
     60   },
     61   "explain" : true,
     62   "aggregations" : {
     63     "agg" : {
     64       "filter" : {
     65         "bool" : {
     66           "must" : [
     67             {
     68               "bool" : {
     69                 "should" : [
     70                   {
     71                     "match" : {
     72                       "tel" : {
     73                         "query" : "18612855433",
     74                         "operator" : "OR",
     75                         "prefix_length" : 0,
     76                         "max_expansions" : 50,
     77                         "fuzzy_transpositions" : true,
     78                         "lenient" : false,
     79                         "zero_terms_query" : "NONE",
     80                         "boost" : 1.0
     81                       }
     82                     }
     83                   }
     84                 ],
     85                 "adjust_pure_negative" : true,
     86                 "boost" : 1.0
     87               }
     88             },
     89             {
     90               "range" : {
     91                 "age" : {
     92                   "from" : 0,
     93                   "to" : 45,
     94                   "include_lower" : true,
     95                   "include_upper" : true,
     96                   "boost" : 1.0
     97                 }
     98               }
     99             }
    100           ],
    101           "adjust_pure_negative" : true,
    102           "boost" : 1.0
    103         }
    104       },
    105       "aggregations" : {
    106         "agg" : {
    107           "terms" : {
    108             "field" : "attr_name",
    109             "size" : 100,
    110             "min_doc_count" : 1,
    111             "shard_min_doc_count" : 0,
    112             "show_term_doc_count_error" : false,
    113             "order" : [
    114               {
    115                 "_count" : "desc"
    116               },
    117               {
    118                 "_key" : "asc"
    119               }
    120             ]
    121           }
    122         }
    123       }
    124     },
    125     "range" : {
    126       "range" : {
    127         "field" : "age",
    128         "ranges" : [
    129           {
    130             "from" : 0.0,
    131             "to" : 30.0
    132           },
    133           {
    134             "from" : 30.0,
    135             "to" : 50.0
    136           },
    137           {
    138             "from" : 50.0,
    139             "to" : 100.0
    140           }
    141         ],
    142         "keyed" : false
    143       }
    144     }
    145   }
    146 }

    查询结果:

      1 {
      2   "took": 1,
      3   "timed_out": false,
      4   "_shards": {
      5     "total": 5,
      6     "successful": 5,
      7     "skipped": 0,
      8     "failed": 0
      9   },
     10   "hits": {
     11     "total": 21,
     12     "max_score": 1,
     13     "hits": [
     14       {
     15         "_index": "red89",
     16         "_type": "test",
     17         "_id": "14",
     18         "_score": 1,
     19         "_source": {
     20           "date": "2017-12-11T09:55:42.261Z",
     21           "attr_name": [
     22             "品牌_sku_attr14",
     23             "商品类别_sku_attr14",
     24             "面料_sku_attr14"
     25           ],
     26           "name": "中华人民共和国14",
     27           "tel": "18612855433",
     28           "message": "程序设计14",
     29           "create_date": "2017-12-11T09:55:42.261Z",
     30           "age": 44
     31         }
     32       },
     33       {
     34         "_index": "red89",
     35         "_type": "test",
     36         "_id": "19",
     37         "_score": 1,
     38         "_source": {
     39           "date": "2017-12-11T09:55:42.261Z",
     40           "attr_name": [
     41             "品牌_sku_attr19",
     42             "商品类别_sku_attr19",
     43             "面料_sku_attr19"
     44           ],
     45           "name": "中华人民共和国19",
     46           "tel": "18612855433",
     47           "message": "程序设计19",
     48           "create_date": "2017-12-11T09:55:42.261Z",
     49           "age": 49
     50         }
     51       },
     52       {
     53         "_index": "red89",
     54         "_type": "test",
     55         "_id": "5",
     56         "_score": 1,
     57         "_source": {
     58           "date": "2017-12-11T09:55:42.257Z",
     59           "attr_name": [
     60             "品牌_sku_attr5",
     61             "商品类别_sku_attr5",
     62             "面料_sku_attr5"
     63           ],
     64           "name": "中华人民共和国5",
     65           "tel": "18612855433",
     66           "message": "程序设计5",
     67           "create_date": "2017-12-11T09:55:42.257Z",
     68           "age": 35
     69         }
     70       },
     71       {
     72         "_index": "red89",
     73         "_type": "test",
     74         "_id": "8",
     75         "_score": 1,
     76         "_source": {
     77           "date": "2017-12-11T09:55:42.257Z",
     78           "attr_name": [
     79             "品牌_sku_attr8",
     80             "商品类别_sku_attr8",
     81             "面料_sku_attr8"
     82           ],
     83           "name": "中华人民共和国8",
     84           "tel": "18612855433",
     85           "message": "程序设计8",
     86           "create_date": "2017-12-11T09:55:42.257Z",
     87           "age": 38
     88         }
     89       },
     90       {
     91         "_index": "red89",
     92         "_type": "test",
     93         "_id": "9",
     94         "_score": 1,
     95         "_source": {
     96           "date": "2017-12-11T09:55:42.257Z",
     97           "attr_name": [
     98             "品牌_sku_attr9",
     99             "商品类别_sku_attr9",
    100             "面料_sku_attr9"
    101           ],
    102           "name": "中华人民共和国9",
    103           "tel": "18612855433",
    104           "message": "程序设计9",
    105           "create_date": "2017-12-11T09:55:42.257Z",
    106           "age": 39
    107         }
    108       },
    109       {
    110         "_index": "red89",
    111         "_type": "test",
    112         "_id": "10",
    113         "_score": 1,
    114         "_source": {
    115           "date": "2017-12-11T09:55:42.257Z",
    116           "attr_name": [
    117             "品牌_sku_attr10",
    118             "商品类别_sku_attr10",
    119             "面料_sku_attr10"
    120           ],
    121           "name": "中华人民共和国10",
    122           "tel": "18612855433",
    123           "message": "程序设计10",
    124           "create_date": "2017-12-11T09:55:42.257Z",
    125           "age": 40
    126         }
    127       },
    128       {
    129         "_index": "red89",
    130         "_type": "test",
    131         "_id": "12",
    132         "_score": 1,
    133         "_source": {
    134           "date": "2017-12-11T09:55:42.261Z",
    135           "attr_name": [
    136             "品牌_sku_attr12",
    137             "商品类别_sku_attr12",
    138             "面料_sku_attr12"
    139           ],
    140           "name": "中华人民共和国12",
    141           "tel": "18612855433",
    142           "message": "程序设计12",
    143           "create_date": "2017-12-11T09:55:42.261Z",
    144           "age": 42
    145         }
    146       },
    147       {
    148         "_index": "red89",
    149         "_type": "test",
    150         "_id": "ZraQK2ABrThwqnonhOO3",
    151         "_score": 1,
    152         "_source": {}
    153       },
    154       {
    155         "_index": "red89",
    156         "_type": "test",
    157         "_id": "2",
    158         "_score": 1,
    159         "_source": {
    160           "date": "2017-12-11T09:55:42.256Z",
    161           "attr_name": [
    162             "品牌_sku_attr2",
    163             "商品类别_sku_attr2",
    164             "面料_sku_attr2"
    165           ],
    166           "name": "中华人民共和国2",
    167           "tel": "18612855433",
    168           "message": "程序设计2",
    169           "create_date": "2017-12-11T09:55:42.256Z",
    170           "age": 32
    171         }
    172       },
    173       {
    174         "_index": "red89",
    175         "_type": "test",
    176         "_id": "4",
    177         "_score": 1,
    178         "_source": {
    179           "date": "2017-12-11T09:55:42.257Z",
    180           "attr_name": [
    181             "品牌_sku_attr4",
    182             "商品类别_sku_attr4",
    183             "面料_sku_attr4"
    184           ],
    185           "name": "中华人民共和国4",
    186           "tel": "18612855433",
    187           "message": "程序设计4",
    188           "create_date": "2017-12-11T09:55:42.257Z",
    189           "age": 34
    190         }
    191       }
    192     ]
    193   }
    194 }
  • 相关阅读:
    Oracle RAC的五大优势及其劣势
    Lucene全文检索基础
    oracle手工生成AWR报告方法记录
    log file sync 等侍值高的一般通用解决办法
    log file sync 因为数据线有问题而造成高等侍的表现
    MongoDB实用教程
    1小时学会JQuery
    Ajax+Struts2实现验证码验证功能
    硬件01:门
    关于软件工程的思考15:人和绩效
  • 原文地址:https://www.cnblogs.com/shoutn/p/8027960.html
Copyright © 2020-2023  润新知