狂神--ElasticSearch

打印 上一主题 下一主题

主题 1012|帖子 1012|积分 3036

一、ElasticSearch概述

官网:https://www.elastic.co/cn/downloads/elasticsearch
Elaticsearch,简称为es,es是一个开源的高扩展分布式全文检索引擎,它可以近乎实时的存储检索数据;本身扩展性很好,可以扩展到上百台服务器,处理PB级别(大数据时代)的数据。es也使用java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单。
据国际权威的数据库产品评测机构DB Engines的统计,在2016年1月,ElasticSearch已超过Solr等,成为排名第一的搜索引擎类应用
总结

1、es基本是开箱即用(解压就可以用!) ,非常简单。Solr安装略微复杂一丢丢!
2、Solr 利用Zookeeper进行分布式管理,而Elasticsearch自身带有分布式协调管理功能。
3、Solr 支持更多格式的数据,比如JSON、XML、 CSV ,而Elasticsearch仅支持json文件格式
4、Solr 官方提供的功能更多,而Elasticsearch本身更注重于核心功能,高级功能多有第三方插件提供,例如图形化界面需要kibana友好支撑
5、Solr 查询快,但更新索引时慢(即插入删除慢) ,用于电商等查询多的应用;

  • ES建立索引快(即查询慢) ,即实时性查询快,用于facebook新浪等搜索。
  • Solr是传统搜索应用的有力解决方案,但Elasticsearch更适用于新兴的实时搜索应用。
6、Solr比较成熟,有一个更大,更成熟的用户、开发和贡献者社区,而Elasticsearch相对开发维护者较少,更新太快,学习使用成本较高。
二、ElasticSearch安装

Windows下安装

1、安装

下载地址:https://www.elastic.co/cn/downloads/
历史版本下载:https://www.elastic.co/cn/downloads/past-releases/
解压即可(尽量将ElasticSearch相关工具放在统一目录下)
2、熟悉目录
  1. bin 启动文件目录
  2. config 配置文件目录   
  3.         1og4j2 日志配置文件   
  4.         jvm.options java 虚拟机相关的配置(默认启动占1g内存,内容不够需要自己调整)   
  5.         elasticsearch.ym1 elasticsearch 的配置文件! 默认9200端口!跨域!
  6. 1ib   相关jar包
  7. modules 功能模块目录
  8. plugins 插件目录   
  9.         ik分词器
复制代码
3、启动

bin目录下的elasticsearch.bat
访问地址: localhost:9200
  1. {
  2.   "name" : "TIANYH",
  3.   "cluster_name" : "elasticsearch",
  4.   "cluster_uuid" : "IOHRCRK6TKibMGdNZq4YtA",
  5.   "version" : {
  6.     "number" : "7.6.1",
  7.     "build_flavor" : "default",
  8.     "build_type" : "zip",
  9.     "build_hash" : "aa751e09be0a5072e8570670309b1f12348f023b",
  10.     "build_date" : "2020-02-29T00:15:25.529771Z",
  11.     "build_snapshot" : false,
  12.     "lucene_version" : "8.4.0",
  13.     "minimum_wire_compatibility_version" : "6.8.0",
  14.     "minimum_index_compatibility_version" : "6.0.0-beta1"
  15.   },
  16.   "tagline" : "You Know, for Search"
  17. }
复制代码
安装可视化界面

  1. elasticsearch-head
复制代码
使用前提:需要安装nodejs
1、下载地址

https://github.com/mobz/elasticsearch-head
2、安装

解压即可(尽量将ElasticSearch相关工具放在统一目录下)
3、启动
  1. cd elasticsearch-head
  2. # 安装依赖npm install
  3. # 启动npm run start#
  4. # 访问http://localhost:9100/
复制代码
开启跨域(在elasticsearch解压目录config下elasticsearch.yml中添加)
  1. # 开启跨域http.cors.enabled: true
  2. # 所有人访问http.cors.allow-origin: "*"
复制代码
重启elasticsearch
理解:

  • 如果你是初学者

    • 索引 可以看做 “数据库”
    • 类型 可以看做 “表”
    • 文档 可以看做 “库中的数据(表中的行)”

  • 这个head,我们只是把它当做可视化数据展示工具,之后所有的查询都在kibana中进行

    • 因为不支持json格式化,不方便

安装kibana

Kibana是一个针对ElasticSearch的开源分析及可视化平台,用来搜索、查看交互存储在Elasticsearch索引中的数据。使用Kibana ,可以通过各种图表进行高级数据分析及展示。Kibana让海量数据更容易理解。它操作简单,基于浏览器的用户界面可以快速创建仪表板( dashboard )实时显示Elasticsearch查询动态。设置Kibana非常简单。无需编码或者额外的基础架构,几分钟内就可以完成Kibana安装并启动Elasticsearch索引监测。
1、下载地址:

下载的版本需要与ElasticSearch版本对应
https://www.elastic.co/cn/downloads/
历史版本下载:https://www.elastic.co/cn/downloads/past-releases/
2、安装

解压即可(尽量将ElasticSearch相关工具放在统一目录下)
3、启动

bin目录下的kibanan.bat
访问地址: localhost:5601
4、kibana汉化

编辑器打开kibana解压目录/config/kibana.yml,添加
  1. i18n.locale: "zh-CN"
复制代码
重启kibana
了解ELK


  • ELK是
    Elasticsearch、Logstash、 Kibana三大开源框架首字母大写简称
    。市面上也被成为Elastic Stack。

    • 其中Elasticsearch是一个基于Lucene、分布式、通过Restful方式进行交互的近实时搜索平台框架。

      • 像类似百度、谷歌这种大数据全文搜索引擎的场景都可以使用Elasticsearch作为底层支持框架,可见Elasticsearch提供的搜索能力确实强大,市面上很多时候我们简称Elasticsearch为es。

    • Logstash是ELK的中央数据流引擎,用于从不同目标(文件/数据存储/MQ )收集的不同格式数据,经过过滤后支持输出到不同目的地(文件/MQ/redis/elasticsearch/kafka等)。
    • Kibana可以将elasticsearch的数据通过友好的页面展示出来 ,提供实时分析的功能。

  • 市面上很多开发只要提到ELK能够一致说出它是一个日志分析架构技术栈总称 ,但实际上ELK不仅仅适用于日志分析,它还可以支持其它任何数据分析和收集的场景,日志分析和收集只是更具有代表性。并非唯一性。
  1. 收集清洗数据(Logstash) ==> 搜索、存储(ElasticSearch) ==> 展示(Kibana)
复制代码
三、ElasticSearch核心概念

概述

1、索引(ElasticSearch)

  • 包多个分片
2、字段类型(映射)

  • 字段类型映射(字段是整型,还是字符型…)
3、文档
4、分片(Lucene索引,倒排索引)
ElasticSearch是面向文档,关系行数据库和ElasticSearch客观对比!一切都是JSON!
Relational DBElasticSearch数据库(database)索引(indices)表(tables)types 行(rows)documents字段(columns)fieldselasticsearch(集群)中可以包含多个索引(数据库) ,每个索引中可以包含多个类型(表) ,每个类型下又包含多个文档(行) ,每个文档中又包含多个字段(列)
物理设计:

elasticsearch在后台把每个索引划分成多个分片,每分分片可以在集群中的不同服务器间迁移
一个人就是一个集群! ,即启动的ElasticSearch服务,默认就是一个集群,且默认集群名为elasticsearch
逻辑设计:

一个索引类型中,包含多个文档,比如说文档1,文档2。当我们索引一篇文档时,可以通过这样的顺序找到它:索引 => 类型 => 文档ID ,通过这个组合我们就能索引到某个具体的文档。 注意:ID不必是整数,实际上它是个字符串。
文档(”行“)

之前说elasticsearch是面向文档的,那么就意味着索引和搜索数据的最小单位是文档,elasticsearch中,文档有几个重要属性:

  • 自我包含,一篇文档同时包含字段和对应的值,也就是同时包含key:value !
  • 可以是层次型的,一个文档中包含自文档,复杂的逻辑实体就是这么来的!
  • 灵活的结构,文档不依赖预先定义的模式,我们知道关系型数据库中,要提前定义字段才能使用,在elasticsearch中,对于字段是非常灵活的,有时候,我们可以忽略该字段,或者动态的添加一个新的字段。
尽管我们可以随意的新增或者忽略某个字段,但是,每个字段的类型非常重要,比如一个年龄字段类型,可以是字符串也可以是整形。因为elasticsearch会保存字段和类型之间的映射及其他的设置。这种映射具体到每个映射的每种类型,这也是为什么在elasticsearch中,类型有时候也称为映射类型。
类型(“表”)

类型是文档的逻辑容器,就像关系型数据库一样,表格是行的容器。类型中对于字段的定义称为映射,比如name映射为字符串类型。我们说文档是无模式的,它们不需要拥有映射中所定义的所有字段,比如新增一个字段,那么elasticsearch是怎么做的呢?

  • elasticsearch会自动的将新字段加入映射,但是这个字段的不确定它是什么类型,elasticsearch就开始猜,如果这个值是18,那么elasticsearch会认为它是整形。但是elasticsearch也可能猜不对,所以最安全的方式就是提前定义好所需要的映射,这点跟关系型数据库殊途同归了,先定义好字段,然后再使用,别整什么幺蛾子。
索引(“库”)

索引是映射类型的容器, elasticsearch中的索引是一个非常大的文档集合。 索引存储了映射类型的字段和其他设置。然后它们被存储到了各个分片上了。我们来研究下分片是如何工作的。
一个集群至少有一个节点,而一个节点就是一个elasricsearch进程,节点可以有多个索引默认的,如果你创建索引,那么索引将会有个5个分片(primary shard ,又称主分片)构成的,每一个主分片会有一个副本(replica shard,又称复制分片)
有3个节点的集群,可以看到主分片和对应的复制分片都不会在同一个节点内,这样有利于某个节点挂掉了,数据也不至于失。实际上,一个分片是一个Lucene索引(一个ElasticSearch索引包含多个Lucene索引)一个包含倒排索引的文件目录,倒排索引的结构使得elasticsearch在不扫描全部文档的情况下,就能告诉你哪些文档包含特定的关键字。不过,等等,倒排索引是什么鬼?
倒排索引(Lucene索引底层)
简单说就是 按(文章关键字,对应的文档)形式建立索引,根据关键字就可直接查询对应的文档(含关键字的),无需查询每一个文档,如下图
四、IK分词器(elasticsearch插件)

IK分词器:中文分词器
分词:即把一段中文或者别的划分成一个个的关键字,我们在搜索时候会把自己的信息进行分词,会把数据库中或者索引库中的数据进行分词,然后进行一一个匹配操作,默认的中文分词是将每个字看成一个词(不使用用IK分词器的情况下),比如“我爱狂神”会被分为”我”,”爱”,”狂”,”神” ,这显然是不符合要求的,所以我们需要安装中文分词器ik来解决这个问题。
IK提供了两个分词算法: ik_smart和ik_max_word ,其中ik_smart为最少切分, ik_max_word为最细粒度划分!
1、下载

版本要与ElasticSearch版本对应
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
2、安装

ik文件夹是自己创建的
加压即可(但是我们需要解压到ElasticSearch的plugins目录ik文件夹下)
4、使用 ElasticSearch安装补录/bin/elasticsearch-plugin 可以查看插件
  1. E:\ElasticSearch\elasticsearch-7.6.1\bin>elasticsearch-plugin list
复制代码
5、使用kibana测试

ik_smart:最少切分
  1. GET _analyze
  2. {
  3.   "analyzer": "ik_smart",
  4.   "text": "白日依山尽
  5. 黄河入海流"
  6. }
  7. {
  8.   "tokens" : [
  9.     {
  10.       "token" : "白日",
  11.       "start_offset" : 0,
  12.       "end_offset" : 2,
  13.       "type" : "CN_WORD",
  14.       "position" : 0
  15.     },
  16.     {
  17.       "token" : "依",
  18.       "start_offset" : 2,
  19.       "end_offset" : 3,
  20.       "type" : "CN_CHAR",
  21.       "position" : 1
  22.     },
  23.     {
  24.       "token" : "山",
  25.       "start_offset" : 3,
  26.       "end_offset" : 4,
  27.       "type" : "CN_CHAR",
  28.       "position" : 2
  29.     },
  30.     {
  31.       "token" : "尽",
  32.       "start_offset" : 4,
  33.       "end_offset" : 5,
  34.       "type" : "CN_CHAR",
  35.       "position" : 3
  36.     },
  37.     {
  38.       "token" : "黄河",
  39.       "start_offset" : 5,
  40.       "end_offset" : 7,
  41.       "type" : "CN_WORD",
  42.       "position" : 4
  43.     },
  44.     {
  45.       "token" : "入海流",
  46.       "start_offset" : 7,
  47.       "end_offset" : 10,
  48.       "type" : "CN_WORD",
  49.       "position" : 5
  50.     }
  51.   ]
  52. }
复制代码
ik_max_word:最细粒度划分(穷尽词库的可能)
  1. GET _analyze
  2. {
  3.   "analyzer": "ik_max_word",
  4.   "text": "白日依山尽
  5. 黄河入海流"
  6. }
  7. {
  8.   "tokens" : [
  9.     {
  10.       "token" : "白日",
  11.       "start_offset" : 0,
  12.       "end_offset" : 2,
  13.       "type" : "CN_WORD",
  14.       "position" : 0
  15.     },
  16.     {
  17.       "token" : "依",
  18.       "start_offset" : 2,
  19.       "end_offset" : 3,
  20.       "type" : "CN_CHAR",
  21.       "position" : 1
  22.     },
  23.     {
  24.       "token" : "山",
  25.       "start_offset" : 3,
  26.       "end_offset" : 4,
  27.       "type" : "CN_CHAR",
  28.       "position" : 2
  29.     },
  30.     {
  31.       "token" : "尽",
  32.       "start_offset" : 4,
  33.       "end_offset" : 5,
  34.       "type" : "CN_CHAR",
  35.       "position" : 3
  36.     },
  37.     {
  38.       "token" : "黄河",
  39.       "start_offset" : 5,
  40.       "end_offset" : 7,
  41.       "type" : "CN_WORD",
  42.       "position" : 4
  43.     },
  44.     {
  45.       "token" : "入海流",
  46.       "start_offset" : 7,
  47.       "end_offset" : 10,
  48.       "type" : "CN_WORD",
  49.       "position" : 5
  50.     },
  51.     {
  52.       "token" : "入海",
  53.       "start_offset" : 7,
  54.       "end_offset" : 9,
  55.       "type" : "CN_WORD",
  56.       "position" : 6
  57.     },
  58.     {
  59.       "token" : "海流",
  60.       "start_offset" : 8,
  61.       "end_offset" : 10,
  62.       "type" : "CN_WORD",
  63.       "position" : 7
  64.     }
  65.   ]
  66. }
复制代码
6、添加自定义的词添加到扩展字典中
  1. elasticsearch目录/plugins/ik/config/IKAnalyzer.cfg.xml
复制代码
打开 IKAnalyzer.cfg.xml 文件,扩展字典
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
  3. <properties>
  4.         <comment>IK Analyzer 扩展配置</comment>
  5.        
  6.         <entry key="ext_dict">my.dic</entry>
  7.          
  8.         <entry key="ext_stopwords"></entry>
  9.        
  10.        
  11.        
  12.        
  13. </properties>
复制代码
编写 my.dic
  1. 白日依山尽
  2. 黄河入海流
复制代码
  1. GET _analyze{  "analyzer": "ik_smart",  "text": "白日依山尽
  2. 黄河入海流"}{  "tokens" : [    {      "token" : "白日依山尽",      "start_offset" : 0,      "end_offset" : 5,      "type" : "CN_WORD",      "position" : 0    },    {      "token" : "黄河入海流",      "start_offset" : 5,      "end_offset" : 10,      "type" : "CN_WORD",      "position" : 1    }  ]}
复制代码
五、Rest风格说明

一种软件架构风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁更有层次更易于实现缓存等机制。
基本Rest命令说明:

methodurl地址描述PUT(创建,修改)localhost:9200/索引名称/类型名称/文档id创建文档(指定文档id)POST(创建)localhost:9200/索引名称/类型名称创建文档(随机文档id)POST(修改)localhost:9200/索引名称/类型名称/文档id/_update修改文档DELETE(删除)localhost:9200/索引名称/类型名称/文档id删除文档GET(查询)localhost:9200/索引名称/类型名称/文档id查询文档通过文档IDPOST(查询)localhost:9200/索引名称/类型名称/文档id/_search查询所有数据测试

1、创建一个索引,添加
  1. PUT /test/type/1
  2. {
  3.   "name": "测试",
  4.   "age": 18
  5. }
  6. {
  7.   "_index" : "test",
  8.   "_type" : "type",
  9.   "_id" : "1",
  10.   "_version" : 1,
  11.   "result" : "created",
  12.   "_shards" : {
  13.     "total" : 2,
  14.     "successful" : 1,
  15.     "failed" : 0
  16.   },
  17.   "_seq_no" : 0,
  18.   "_primary_term" : 1
  19. }
复制代码
2、字段数据类型


  • 字符串类型

    • text、
      keyword

      • text:支持分词,全文检索,支持模糊、精确查询,不支持聚合,排序操作;text类型的最大支持的字符长度无限制,适合大字段存储;
      • keyword:不进行分词,直接索引、支持模糊、支持精确匹配,支持聚合、排序操作。keyword类型的最大支持的长度为——32766个UTF-8类型的字符,可以通过设置ignore_above指定自持字符长度,超过给定长度后的数据将不被索引,无法通过term精确匹配检索返回结果。


  • 数值型

    • long、Integer、short、byte、double、float、half floatscaled float

  • 日期类型

    • date

  • te布尔类型

    • boolean

  • 二进制类型

    • binary

  • 等等…
3、指定字段的类型(使用PUT)

类似于建库(建立索引和字段对应类型),也可看做规则的建立
  1. PUT /test2
  2. {
  3.   "mappings": {
  4.     "properties": {
  5.       "name": {
  6.    
  7.     "type": "text"
  8.       },
  9.       "age":{
  10.    
  11.     "type": "long"
  12.       },
  13.       "birthday":{
  14.    
  15.     "type": "date"
  16.       }
  17.     }
  18.   }
  19. }
  20. {
  21.   "acknowledged" : true,
  22.   "shards_acknowledged" : true,
  23.   "index" : "test2"
  24. }
复制代码
4、获取3建立的规则
  1. GET test2
  2. {
  3.   "test2" : {
  4.     "aliases" : { },
  5.     "mappings" : {
  6.       "properties" : {
  7.    
  8.     "age" : {
  9.    
  10.       "type" : "long"
  11.    
  12.     },
  13.    
  14.     "birthday" : {
  15.    
  16.       "type" : "date"
  17.    
  18.     },
  19.    
  20.     "name" : {
  21.    
  22.       "type" : "text"
  23.    
  24.     }
  25.       }
  26.     },
  27.     "settings" : {
  28.       "index" : {
  29.    
  30.     "creation_date" : "1676438148562",
  31.    
  32.     "number_of_shards" : "1",
  33.    
  34.     "number_of_replicas" : "1",
  35.    
  36.     "uuid" : "d-qUkOZKQJKzd68KHiN_pw",
  37.    
  38.     "version" : {
  39.    
  40.       "created" : "7060199"
  41.    
  42.     },
  43.    
  44.     "provided_name" : "test2"
  45.       }
  46.     }
  47.   }
  48. }
复制代码
5、获取默认信息

_doc 默认类型(default type),type 在未来的版本中会逐渐弃用,因此产生一个默认类型进行代替
  1. PUT /test3/_doc/1
  2. {
  3.   "name": "黄河",
  4.   "age": 18
  5. }
  6. {
  7.   "_index" : "test3",
  8.   "_type" : "_doc",
  9.   "_id" : "1",
  10.   "_version" : 1,
  11.   "result" : "created",
  12.   "_shards" : {
  13.     "total" : 2,
  14.     "successful" : 1,
  15.     "failed" : 0
  16.   },
  17.   "_seq_no" : 0,
  18.   "_primary_term" : 1
  19. }
  20. GET test3
  21. {
  22.   "test3" : {
  23.     "aliases" : { },
  24.     "mappings" : {
  25.       "properties" : {
  26.    
  27.     "age" : {
  28.    
  29.       "type" : "long"
  30.    
  31.     },
  32.    
  33.     "name" : {
  34.    
  35.       "type" : "text",
  36.    
  37.       "fields" : {
  38.    
  39.         "keyword" : {
  40.    
  41.           "type" : "keyword",
  42.    
  43.           "ignore_above" : 256
  44.    
  45.         }
  46.    
  47.       }
  48.    
  49.     }
  50.       }
  51.     },
  52.     "settings" : {
  53.       "index" : {
  54.    
  55.     "creation_date" : "1676438576004",
  56.    
  57.     "number_of_shards" : "1",
  58.    
  59.     "number_of_replicas" : "1",
  60.    
  61.     "uuid" : "QmHErZuzSvmczgtgyzC7oA",
  62.    
  63.     "version" : {
  64.    
  65.       "created" : "7060199"
  66.    
  67.     },
  68.    
  69.     "provided_name" : "test3"
  70.       }
  71.     }
  72.   }
  73. }
复制代码
如果自己的文档字段没有被指定,那么ElasticSearch就会给我们默认配置字段类型
扩展:通过GET _cat/ 可以获取ElasticSearch的当前的很多信息!
  1. =^.^=
  2. /_cat/allocation
  3. /_cat/shards
  4. /_cat/shards/{index}
  5. /_cat/master
  6. /_cat/nodes
  7. /_cat/tasks
  8. /_cat/indices
  9. /_cat/indices/{index}
  10. /_cat/segments
  11. /_cat/segments/{index}
  12. /_cat/count
  13. /_cat/count/{index}
  14. /_cat/recovery
  15. /_cat/recovery/{index}
  16. /_cat/health
  17. /_cat/pending_tasks
  18. /_cat/aliases
  19. /_cat/aliases/{alias}
  20. /_cat/thread_pool
  21. /_cat/thread_pool/{thread_pools}
  22. /_cat/plugins
  23. /_cat/fielddata
  24. /_cat/fielddata/{fields}
  25. /_cat/nodeattrs
  26. /_cat/repositories
  27. /_cat/snapshots/{repository}
  28. /_cat/templates
复制代码
6、修改

两种方案
①旧的(使用put覆盖原来的值)

  • 版本+1(_version)
  • 但是如果漏掉某个字段没有写,那么更新是没有写的字段 ,会消失
  1. PUT /test/type/1
  2. {
  3.   "name": "测试",
  4.   "age": 19
  5. }
  6. GET /test/_doc/1
  7. {
  8.   "_index" : "test",
  9.   "_type" : "_doc",
  10.   "_id" : "1",
  11.   "_version" : 2,
  12.   "_seq_no" : 1,
  13.   "_primary_term" : 1,
  14.   "found" : true,
  15.   "_source" : {
  16.     "name" : "测试",
  17.     "age" : 19
  18.   }
  19. }
  20. PUT /test/type/1
  21. {
  22.   "age": 20
  23. }
  24. GET /test/_doc/1
  25. {
  26.   "_index" : "test",
  27.   "_type" : "_doc",
  28.   "_id" : "1",
  29.   "_version" : 3,
  30.   "_seq_no" : 2,
  31.   "_primary_term" : 1,
  32.   "found" : true,
  33.   "_source" : {
  34.     "age" : 20
  35.   }
  36. }
复制代码
②新的(使用post的update)

  • version不会改变
  • 需要注意doc
  • 不会丢失字段
  1. POST /test/_doc/1/_update
  2. {
  3.   "doc":{
  4.     "age":11
  5.   }
  6. }
  7. GET /test/_doc/1
  8. {
  9.   "_index" : "test",
  10.   "_type" : "_doc",
  11.   "_id" : "1",
  12.   "_version" : 5,
  13.   "_seq_no" : 4,
  14.   "_primary_term" : 1,
  15.   "found" : true,
  16.   "_source" : {
  17.     "name" : "测试",
  18.     "age" : 11
  19.   }
  20. }
复制代码
7、删除
  1. DELETE /test
  2. {
  3.   "acknowledged" : true
  4. }
复制代码
8、查询(简单条件)
  1. GET /test/_doc/_search?q=age:19
  2. {
  3.   "took" : 1,
  4.   "timed_out" : false,
  5.   "_shards" : {
  6.     "total" : 1,
  7.     "successful" : 1,
  8.     "skipped" : 0,
  9.     "failed" : 0
  10.   },
  11.   "hits" : {
  12.     "total" : {
  13.       "value" : 1,
  14.       "relation" : "eq"
  15.     },
  16.     "max_score" : 1.0,
  17.     "hits" : [
  18.       {
  19.    
  20.     "_index" : "test",
  21.    
  22.     "_type" : "_doc",
  23.    
  24.     "_id" : "1",
  25.    
  26.     "_score" : 1.0,
  27.    
  28.     "_source" : {
  29.    
  30.       "name" : "测试",
  31.    
  32.       "age" : 19
  33.    
  34.     }
  35.       }
  36.     ]
  37.   }
  38. }
复制代码
9、复杂查询

①查询匹配


  • match:匹配(会使用分词器解析(先分析文档,然后进行查询))
  • _source:过滤字段
  • sort:排序
  • form、size 分页
  1. GET /test/_doc/_search
  2. {
  3.   
  4. }
  5. {
  6.   "took" : 0,
  7.   "timed_out" : false,
  8.   "_shards" : {
  9.     "total" : 1,
  10.     "successful" : 1,
  11.     "skipped" : 0,
  12.     "failed" : 0
  13.   },
  14.   "hits" : {
  15.     "total" : {
  16.       "value" : 5,
  17.       "relation" : "eq"
  18.     },
  19.     "max_score" : 1.0,
  20.     "hits" : [
  21.       {
  22.    
  23.     "_index" : "test",
  24.    
  25.     "_type" : "_doc",
  26.    
  27.     "_id" : "1",
  28.    
  29.     "_score" : 1.0,
  30.    
  31.     "_source" : {
  32.    
  33.       "name" : "测试",
  34.    
  35.       "age" : 19
  36.    
  37.     }
  38.       },
  39.       {
  40.    
  41.     "_index" : "test",
  42.    
  43.     "_type" : "_doc",
  44.    
  45.     "_id" : "2",
  46.    
  47.     "_score" : 1.0,
  48.    
  49.     "_source" : {
  50.    
  51.       "name" : "小李",
  52.    
  53.       "age" : 19
  54.    
  55.     }
  56.       },
  57.       {
  58.    
  59.     "_index" : "test",
  60.    
  61.     "_type" : "_doc",
  62.    
  63.     "_id" : "3",
  64.    
  65.     "_score" : 1.0,
  66.    
  67.     "_source" : {
  68.    
  69.       "name" : "小张",
  70.    
  71.       "age" : 18
  72.    
  73.     }
  74.       },
  75.       {
  76.    
  77.     "_index" : "test",
  78.    
  79.     "_type" : "_doc",
  80.    
  81.     "_id" : "4",
  82.    
  83.     "_score" : 1.0,
  84.    
  85.     "_source" : {
  86.    
  87.       "name" : "小明",
  88.    
  89.       "age" : 16
  90.    
  91.     }
  92.       },
  93.       {
  94.    
  95.     "_index" : "test",
  96.    
  97.     "_type" : "_doc",
  98.    
  99.     "_id" : "5",
  100.    
  101.     "_score" : 1.0,
  102.    
  103.     "_source" : {
  104.    
  105.       "name" : "明明",
  106.    
  107.       "age" : 16
  108.    
  109.     }
  110.       }
  111.     ]
  112.   }
  113. }
复制代码
  1. GET /test/_doc/_search
  2. {
  3.   "query":{
  4.     "match":{
  5.       "name":"明"
  6.     }
  7.   },
  8.   "_source":["age","name"],
  9.   "sort":[{"age":{"order":"asc"}}],
  10.   "from":0,
  11.   "size":20
  12. }
  13. {
  14.   "took" : 0,
  15.   "timed_out" : false,
  16.   "_shards" : {
  17.     "total" : 1,
  18.     "successful" : 1,
  19.     "skipped" : 0,
  20.     "failed" : 0
  21.   },
  22.   "hits" : {
  23.     "total" : {
  24.       "value" : 2,
  25.       "relation" : "eq"
  26.     },
  27.     "max_score" : null,
  28.     "hits" : [
  29.       {
  30.    
  31.     "_index" : "test",
  32.    
  33.     "_type" : "_doc",
  34.    
  35.     "_id" : "4",
  36.    
  37.     "_score" : null,
  38.    
  39.     "_source" : {
  40.    
  41.       "name" : "小明",
  42.    
  43.       "age" : 16
  44.    
  45.     },
  46.    
  47.     "sort" : [
  48.    
  49.       16
  50.    
  51.     ]
  52.       },
  53.       {
  54.    
  55.     "_index" : "test",
  56.    
  57.     "_type" : "_doc",
  58.    
  59.     "_id" : "5",
  60.    
  61.     "_score" : null,
  62.    
  63.     "_source" : {
  64.    
  65.       "name" : "明明",
  66.    
  67.       "age" : 16
  68.    
  69.     },
  70.    
  71.     "sort" : [
  72.    
  73.       16
  74.    
  75.     ]
  76.       }
  77.     ]
  78.   }
  79. }
复制代码
②多条件查询(bool)


  • must 相当于 and
  • should 相当于 or
  • must_not 相当于 not (... and ...)
  • filter 过滤
  1. GET /test/_doc/_search
  2. {
  3.   "query":{
  4.     "bool":{
  5.       "must":[{"match":{"age":16}},{"match":{"name":"小"}}],
  6.       "filter":{
  7.    
  8.     "range":{
  9.    
  10.     "age":{
  11.    
  12.       "gte":15,
  13.    
  14.       "lte":17
  15.    
  16.       }
  17.    
  18.     }
  19.       }
  20.     }
  21.   }
  22. }
  23. {
  24.   "took" : 1,
  25.   "timed_out" : false,
  26.   "_shards" : {
  27.     "total" : 1,
  28.     "successful" : 1,
  29.     "skipped" : 0,
  30.     "failed" : 0
  31.   },
  32.   "hits" : {
  33.     "total" : {
  34.       "value" : 4,
  35.       "relation" : "eq"
  36.     },
  37.     "max_score" : 1.2940125,
  38.     "hits" : [
  39.       {
  40.    
  41.     "_index" : "test",
  42.    
  43.     "_type" : "_doc",
  44.    
  45.     "_id" : "4",
  46.    
  47.     "_score" : 1.2940125,
  48.    
  49.     "_source" : {
  50.    
  51.       "name" : "小明",
  52.    
  53.       "age" : 16
  54.    
  55.     }
  56.       },
  57.       {
  58.    
  59.     "_index" : "test",
  60.    
  61.     "_type" : "_doc",
  62.    
  63.     "_id" : "6",
  64.    
  65.     "_score" : 1.2940125,
  66.    
  67.     "_source" : {
  68.    
  69.       "name" : "小黄",
  70.    
  71.       "age" : 16
  72.    
  73.     }
  74.       },
  75.       {
  76.    
  77.     "_index" : "test",
  78.    
  79.     "_type" : "_doc",
  80.    
  81.     "_id" : "7",
  82.    
  83.     "_score" : 1.2940125,
  84.    
  85.     "_source" : {
  86.    
  87.       "name" : "小黑",
  88.    
  89.       "age" : 16
  90.    
  91.     }
  92.       },
  93.       {
  94.    
  95.     "_index" : "test",
  96.    
  97.     "_type" : "_doc",
  98.    
  99.     "_id" : "9",
  100.    
  101.     "_score" : 1.2940125,
  102.    
  103.     "_source" : {
  104.    
  105.       "name" : "小花",
  106.    
  107.       "age" : 16
  108.    
  109.     }
  110.       }
  111.     ]
  112.   }
  113. }
复制代码
③匹配数组


  • 貌似不能与其它字段一起使用
  • 可以多关键字查(空格隔开)— 匹配字段也是符合的
  • match 会使用分词器解析(先分析文档,然后进行查询)
  • 搜词
  1. GET /test/_doc/_search
  2. {
  3.   "query":{
  4.     "match":{
  5.       "name":"明 黑"
  6.     }
  7.   }
  8. }
  9. {
  10.   "took" : 1,
  11.   "timed_out" : false,
  12.   "_shards" : {
  13.     "total" : 1,
  14.     "successful" : 1,
  15.     "skipped" : 0,
  16.     "failed" : 0
  17.   },
  18.   "hits" : {
  19.     "total" : {
  20.       "value" : 3,
  21.       "relation" : "eq"
  22.     },
  23.     "max_score" : 1.9388659,
  24.     "hits" : [
  25.       {
  26.    
  27.     "_index" : "test",
  28.    
  29.     "_type" : "_doc",
  30.    
  31.     "_id" : "7",
  32.    
  33.     "_score" : 1.9388659,
  34.    
  35.     "_source" : {
  36.    
  37.       "name" : "小黑",
  38.    
  39.       "age" : 16
  40.    
  41.     }
  42.       },
  43.       {
  44.    
  45.     "_index" : "test",
  46.    
  47.     "_type" : "_doc",
  48.    
  49.     "_id" : "5",
  50.    
  51.     "_score" : 1.4651942,
  52.    
  53.     "_source" : {
  54.    
  55.       "name" : "明明",
  56.    
  57.       "age" : 16
  58.    
  59.     }
  60.       },
  61.       {
  62.    
  63.     "_index" : "test",
  64.    
  65.     "_type" : "_doc",
  66.    
  67.     "_id" : "4",
  68.    
  69.     "_score" : 1.0729234,
  70.    
  71.     "_source" : {
  72.    
  73.       "name" : "小明",
  74.    
  75.       "age" : 16
  76.    
  77.     }
  78.       }
  79.     ]
  80.   }
  81. }
复制代码
④精确查询


  • term 直接通过 倒排索引 指定词条查询
  • 适合查询 number、date、keyword ,不适合text
  1. GET /test/_doc/_search
  2. {
  3.   "query":{
  4.     "term":{
  5.       "age":16
  6.     }
  7.   }
  8. }
  9. {
  10.   "took" : 0,
  11.   "timed_out" : false,
  12.   "_shards" : {
  13.     "total" : 1,
  14.     "successful" : 1,
  15.     "skipped" : 0,
  16.     "failed" : 0
  17.   },
  18.   "hits" : {
  19.     "total" : {
  20.       "value" : 5,
  21.       "relation" : "eq"
  22.     },
  23.     "max_score" : 1.0,
  24.     "hits" : [
  25.       {
  26.    
  27.     "_index" : "test",
  28.    
  29.     "_type" : "_doc",
  30.    
  31.     "_id" : "4",
  32.    
  33.     "_score" : 1.0,
  34.    
  35.     "_source" : {
  36.    
  37.       "name" : "小明",
  38.    
  39.       "age" : 16
  40.    
  41.     }
  42.       },
  43.       {
  44.    
  45.     "_index" : "test",
  46.    
  47.     "_type" : "_doc",
  48.    
  49.     "_id" : "5",
  50.    
  51.     "_score" : 1.0,
  52.    
  53.     "_source" : {
  54.    
  55.       "name" : "明明",
  56.    
  57.       "age" : 16
  58.    
  59.     }
  60.       },
  61.       {
  62.    
  63.     "_index" : "test",
  64.    
  65.     "_type" : "_doc",
  66.    
  67.     "_id" : "6",
  68.    
  69.     "_score" : 1.0,
  70.    
  71.     "_source" : {
  72.    
  73.       "name" : "小黄",
  74.    
  75.       "age" : 16
  76.    
  77.     }
  78.       },
  79.       {
  80.    
  81.     "_index" : "test",
  82.    
  83.     "_type" : "_doc",
  84.    
  85.     "_id" : "7",
  86.    
  87.     "_score" : 1.0,
  88.    
  89.     "_source" : {
  90.    
  91.       "name" : "小黑",
  92.    
  93.       "age" : 16
  94.    
  95.     }
  96.       },
  97.       {
  98.    
  99.     "_index" : "test",
  100.    
  101.     "_type" : "_doc",
  102.    
  103.     "_id" : "9",
  104.    
  105.     "_score" : 1.0,
  106.    
  107.     "_source" : {
  108.    
  109.       "name" : "小花",
  110.    
  111.       "age" : 16
  112.    
  113.     }
  114.       }
  115.     ]
  116.   }
  117. }
复制代码
⑤text和keyword


  • text:

    • 支持分词全文检索、支持模糊、精确查询,不支持聚合,排序操作;
    • text类型的最大支持的字符长度无限制,适合大字段存储;

  • keyword:

    • 不进行分词直接索引、支持模糊、支持精确匹配,支持聚合、排序操作。
    • keyword类型的最大支持的长度为——32766个UTF-8类型的字符,可以通过设置ignore_above指定自持字符长度,超过给定长度后的数据将不被索引,无法通过term精确匹配检索返回结果

  1. // 设置索引类型
  2. PUT /test2
  3. {
  4.   "mappings": {
  5.     "properties": {
  6.       "text":{
  7.    
  8.     "type":"text"
  9.       },
  10.       "keyword":{
  11.    
  12.     "type":"keyword"
  13.       }
  14.     }
  15.   }
  16. }
  17. // 设置字段数据
  18. PUT /test2/_doc/1
  19. {
  20.   "text":"测试keyword和text是否支持分词",
  21.   "keyword":"测试keyword和text是否支持分词"
  22. }
  23. GET /test2/_doc/_search
  24. {
  25.   "query":{
  26.    "match":{
  27.       "text":"测试"
  28.    }
  29.   }
  30. }
  31. {
  32.   "took" : 426,
  33.   "timed_out" : false,
  34.   "_shards" : {
  35.     "total" : 1,
  36.     "successful" : 1,
  37.     "skipped" : 0,
  38.     "failed" : 0
  39.   },
  40.   "hits" : {
  41.     "total" : {
  42.       "value" : 1,
  43.       "relation" : "eq"
  44.     },
  45.     "max_score" : 0.5753642,
  46.     "hits" : [
  47.       {
  48.    
  49.     "_index" : "test2",
  50.    
  51.     "_type" : "_doc",
  52.    
  53.     "_id" : "1",
  54.    
  55.     "_score" : 0.5753642,
  56.    
  57.     "_source" : {
  58.    
  59.       "text" : "测试keyword和text是否支持分词",
  60.    
  61.       "keyword" : "测试keyword和text是否支持分词"
  62.    
  63.     }
  64.       }
  65.     ]
  66.   }
  67. }
  68. GET /test2/_doc/_search
  69. {
  70.   "query":{
  71.    "match":{
  72.       "keyword":"测试"
  73.    }
  74.   }
  75. }
  76. {
  77.   "took" : 0,
  78.   "timed_out" : false,
  79.   "_shards" : {
  80.     "total" : 1,
  81.     "successful" : 1,
  82.     "skipped" : 0,
  83.     "failed" : 0
  84.   },
  85.   "hits" : {
  86.     "total" : {
  87.       "value" : 0,
  88.       "relation" : "eq"
  89.     },
  90.     "max_score" : null,
  91.     "hits" : [ ]
  92.   }
  93. }
  94. GET _analyze
  95. {
  96.   "analyzer": "keyword",
  97.   "text": ["白日依山尽"]
  98. }
  99. {
  100.   "tokens" : [
  101.     {
  102.       "token" : "白日依山尽",
  103.       "start_offset" : 0,
  104.       "end_offset" : 5,
  105.       "type" : "word",
  106.       "position" : 0
  107.     }
  108.   ]
  109. }
  110. GET _analyze
  111. {
  112.   "analyzer": "standard",
  113.     "text": ["白日依山尽"]
  114. }
  115. {
  116.   "tokens" : [
  117.     {
  118.       "token" : "白",
  119.       "start_offset" : 0,
  120.       "end_offset" : 1,
  121.       "type" : "<IDEOGRAPHIC>",
  122.       "position" : 0
  123.     },
  124.     {
  125.       "token" : "日",
  126.       "start_offset" : 1,
  127.       "end_offset" : 2,
  128.       "type" : "<IDEOGRAPHIC>",
  129.       "position" : 1
  130.     },
  131.     {
  132.       "token" : "依",
  133.       "start_offset" : 2,
  134.       "end_offset" : 3,
  135.       "type" : "<IDEOGRAPHIC>",
  136.       "position" : 2
  137.     },
  138.     {
  139.       "token" : "山",
  140.       "start_offset" : 3,
  141.       "end_offset" : 4,
  142.       "type" : "<IDEOGRAPHIC>",
  143.       "position" : 3
  144.     },
  145.     {
  146.       "token" : "尽",
  147.       "start_offset" : 4,
  148.       "end_offset" : 5,
  149.       "type" : "<IDEOGRAPHIC>",
  150.       "position" : 4
  151.     }
  152.   ]
  153. }
  154. GET _analyze
  155. {
  156.   "analyzer": "ik_max_word",
  157.     "text": ["白日依山尽"]
  158. }
  159. {
  160.   "tokens" : [
  161.     {
  162.       "token" : "白日依山尽",
  163.       "start_offset" : 0,
  164.       "end_offset" : 5,
  165.       "type" : "CN_WORD",
  166.       "position" : 0
  167.     },
  168.     {
  169.       "token" : "白日",
  170.       "start_offset" : 0,
  171.       "end_offset" : 2,
  172.       "type" : "CN_WORD",
  173.       "position" : 1
  174.     },
  175.     {
  176.       "token" : "依",
  177.       "start_offset" : 2,
  178.       "end_offset" : 3,
  179.       "type" : "CN_CHAR",
  180.       "position" : 2
  181.     },
  182.     {
  183.       "token" : "山",
  184.       "start_offset" : 3,
  185.       "end_offset" : 4,
  186.       "type" : "CN_CHAR",
  187.       "position" : 3
  188.     },
  189.     {
  190.       "token" : "尽",
  191.       "start_offset" : 4,
  192.       "end_offset" : 5,
  193.       "type" : "CN_CHAR",
  194.       "position" : 4
  195.     }
  196.   ]
  197. }
复制代码
⑥高亮查询
  1. GET /test/_doc/_search
  2. {
  3.     "query":{
  4.    
  5.     "match":{"name":"小"}
  6.     },
  7.    
  8.     "highlight":{
  9.       "fields":{
  10.    
  11.     "name":{}
  12.       }
  13.     }
  14.   
  15. }
  16. {
  17.   "took" : 89,
  18.   "timed_out" : false,
  19.   "_shards" : {
  20.     "total" : 1,
  21.     "successful" : 1,
  22.     "skipped" : 0,
  23.     "failed" : 0
  24.   },
  25.   "hits" : {
  26.     "total" : {
  27.       "value" : 6,
  28.       "relation" : "eq"
  29.     },
  30.     "max_score" : 0.18681718,
  31.     "hits" : [
  32.       {
  33.    
  34.     "_index" : "test",
  35.    
  36.     "_type" : "_doc",
  37.    
  38.     "_id" : "2",
  39.    
  40.     "_score" : 0.18681718,
  41.    
  42.     "_source" : {
  43.    
  44.       "name" : "小李",
  45.    
  46.       "age" : 19
  47.    
  48.     },
  49.    
  50.     "highlight" : {
  51.    
  52.       "name" : [
  53.    
  54.         "<em>小</em>李"
  55.    
  56.       ]
  57.    
  58.     }
  59.       },
  60.       {
  61.    
  62.     "_index" : "test",
  63.    
  64.     "_type" : "_doc",
  65.    
  66.     "_id" : "3",
  67.    
  68.     "_score" : 0.18681718,
  69.    
  70.     "_source" : {
  71.    
  72.       "name" : "小张",
  73.    
  74.       "age" : 18
  75.    
  76.     },
  77.    
  78.     "highlight" : {
  79.    
  80.       "name" : [
  81.    
  82.         "<em>小</em>张"
  83.    
  84.       ]
  85.    
  86.     }
  87.       },
  88.       {
  89.    
  90.     "_index" : "test",
  91.    
  92.     "_type" : "_doc",
  93.    
  94.     "_id" : "4",
  95.    
  96.     "_score" : 0.18681718,
  97.    
  98.     "_source" : {
  99.    
  100.       "name" : "小明",
  101.    
  102.       "age" : 16
  103.    
  104.     },
  105.    
  106.     "highlight" : {
  107.    
  108.       "name" : [
  109.    
  110.         "<em>小</em>明"
  111.    
  112.       ]
  113.    
  114.     }
  115.       },
  116.       {
  117.    
  118.     "_index" : "test",
  119.    
  120.     "_type" : "_doc",
  121.    
  122.     "_id" : "6",
  123.    
  124.     "_score" : 0.18681718,
  125.    
  126.     "_source" : {
  127.    
  128.       "name" : "小黄",
  129.    
  130.       "age" : 16
  131.    
  132.     },
  133.    
  134.     "highlight" : {
  135.    
  136.       "name" : [
  137.    
  138.         "<em>小</em>黄"
  139.    
  140.       ]
  141.    
  142.     }
  143.       },
  144.       {
  145.    
  146.     "_index" : "test",
  147.    
  148.     "_type" : "_doc",
  149.    
  150.     "_id" : "7",
  151.    
  152.     "_score" : 0.18681718,
  153.    
  154.     "_source" : {
  155.    
  156.       "name" : "小黑",
  157.    
  158.       "age" : 16
  159.    
  160.     },
  161.    
  162.     "highlight" : {
  163.    
  164.       "name" : [
  165.    
  166.         "<em>小</em>黑"
  167.    
  168.       ]
  169.    
  170.     }
  171.       },
  172.       {
  173.    
  174.     "_index" : "test",
  175.    
  176.     "_type" : "_doc",
  177.    
  178.     "_id" : "9",
  179.    
  180.     "_score" : 0.18681718,
  181.    
  182.     "_source" : {
  183.    
  184.       "name" : "小花",
  185.    
  186.       "age" : 16
  187.    
  188.     },
  189.    
  190.     "highlight" : {
  191.    
  192.       "name" : [
  193.    
  194.         "<em>小</em>花"
  195.    
  196.       ]
  197.    
  198.     }
  199.       }
  200.     ]
  201.   }
  202. }
  203. GET /test/_doc/_search
  204. {
  205.     "query":{
  206.    
  207.     "match":{"name":"小"}
  208.     },
  209.    
  210.   "highlight": {
  211.     "pre_tags": "<p class='key' style='color:red'>",
  212.     "post_tags": "</p>",
  213.     "fields": {
  214.       "name": {}
  215.     }
  216.   }
  217.   
  218. }
  219. {
  220.   "took" : 2,
  221.   "timed_out" : false,
  222.   "_shards" : {
  223.     "total" : 1,
  224.     "successful" : 1,
  225.     "skipped" : 0,
  226.     "failed" : 0
  227.   },
  228.   "hits" : {
  229.     "total" : {
  230.       "value" : 6,
  231.       "relation" : "eq"
  232.     },
  233.     "max_score" : 0.18681718,
  234.     "hits" : [
  235.       {
  236.    
  237.     "_index" : "test",
  238.    
  239.     "_type" : "_doc",
  240.    
  241.     "_id" : "2",
  242.    
  243.     "_score" : 0.18681718,
  244.    
  245.     "_source" : {
  246.    
  247.       "name" : "小李",
  248.    
  249.       "age" : 19
  250.    
  251.     },
  252.    
  253.     "highlight" : {
  254.    
  255.       "name" : [
  256.    
  257.         "<p class='key' style='color:red'>小</p>李"
  258.    
  259.       ]
  260.    
  261.     }
  262.       },
  263.       {
  264.    
  265.     "_index" : "test",
  266.    
  267.     "_type" : "_doc",
  268.    
  269.     "_id" : "3",
  270.    
  271.     "_score" : 0.18681718,
  272.    
  273.     "_source" : {
  274.    
  275.       "name" : "小张",
  276.    
  277.       "age" : 18
  278.    
  279.     },
  280.    
  281.     "highlight" : {
  282.    
  283.       "name" : [
  284.    
  285.         "<p class='key' style='color:red'>小</p>张"
  286.    
  287.       ]
  288.    
  289.     }
  290.       },
  291.       {
  292.    
  293.     "_index" : "test",
  294.    
  295.     "_type" : "_doc",
  296.    
  297.     "_id" : "4",
  298.    
  299.     "_score" : 0.18681718,
  300.    
  301.     "_source" : {
  302.    
  303.       "name" : "小明",
  304.    
  305.       "age" : 16
  306.    
  307.     },
  308.    
  309.     "highlight" : {
  310.    
  311.       "name" : [
  312.    
  313.         "<p class='key' style='color:red'>小</p>明"
  314.    
  315.       ]
  316.    
  317.     }
  318.       },
  319.       {
  320.    
  321.     "_index" : "test",
  322.    
  323.     "_type" : "_doc",
  324.    
  325.     "_id" : "6",
  326.    
  327.     "_score" : 0.18681718,
  328.    
  329.     "_source" : {
  330.    
  331.       "name" : "小黄",
  332.    
  333.       "age" : 16
  334.    
  335.     },
  336.    
  337.     "highlight" : {
  338.    
  339.       "name" : [
  340.    
  341.         "<p class='key' style='color:red'>小</p>黄"
  342.    
  343.       ]
  344.    
  345.     }
  346.       },
  347.       {
  348.    
  349.     "_index" : "test",
  350.    
  351.     "_type" : "_doc",
  352.    
  353.     "_id" : "7",
  354.    
  355.     "_score" : 0.18681718,
  356.    
  357.     "_source" : {
  358.    
  359.       "name" : "小黑",
  360.    
  361.       "age" : 16
  362.    
  363.     },
  364.    
  365.     "highlight" : {
  366.    
  367.       "name" : [
  368.    
  369.         "<p class='key' style='color:red'>小</p>黑"
  370.    
  371.       ]
  372.    
  373.     }
  374.       },
  375.       {
  376.    
  377.     "_index" : "test",
  378.    
  379.     "_type" : "_doc",
  380.    
  381.     "_id" : "9",
  382.    
  383.     "_score" : 0.18681718,
  384.    
  385.     "_source" : {
  386.    
  387.       "name" : "小花",
  388.    
  389.       "age" : 16
  390.    
  391.     },
  392.    
  393.     "highlight" : {
  394.    
  395.       "name" : [
  396.    
  397.         "<p class='key' style='color:red'>小</p>花"
  398.    
  399.       ]
  400.    
  401.     }
  402.       }
  403.     ]
  404.   }
  405. }
复制代码
六、SpringBoot整合

1、导入依赖

导入elasticsearch
  1. <dependency>   
  2.     <groupId>org.springframework.boot</groupId>   
  3.     <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  4. </dependency>
复制代码
提前导入fastjson、lombok
  1. <dependency>   
  2.     <groupId>com.alibaba</groupId>   
  3.     <artifactId>fastjson</artifactId>   
  4.     <version>1.2.70</version>
  5. </dependency>
  6. <dependency>   
  7.     <groupId>org.projectlombok</groupId>   
  8.     <artifactId>lombok</artifactId>   
  9.     <optional>true</optional>
  10. </dependency>
复制代码
2、创建并编写配置类
  1. @Configuration
  2. public class ElasticSearchConfig {
  3.         // 注册 rest高级客户端
  4.         @Bean
  5.         public RestHighLevelClient restHighLevelClient(){
  6.                 RestHighLevelClient client = new RestHighLevelClient(
  7.                                 RestClient.builder(
  8.                                                 new HttpHost("localhost",9200,"http")
  9.                                 )
  10.                 );
  11.                 return client;
  12.         }
  13. }
复制代码
3、创建并编写实体类
  1. @Data
  2. @NoArgsConstructor
  3. @AllArgsConstructor
  4. public class User implements Serializable {
  5.         private static final long serialVersionUID = -3843548915035470817L;
  6.         private String name;
  7.         private Integer age;
  8. }
复制代码
4、测试

注入 RestHighLevelClient
  1.     @Autowired
  2.     public RestHighLevelClient restHighLevelClient;
复制代码
索引的操作

1、索引的创建
  1.     public void CreatIndex() throws IOException {
  2.    
  3.     CreateIndexRequest request = new CreateIndexRequest("test6");
  4.    
  5.     CreateIndexResponse response = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
  6.    
  7.     System.out.println(response.isAcknowledged());
  8.    
  9.     System.out.println(response);
  10.    
  11.     restHighLevelClient.close();
  12.    
  13.     return ;
  14.     }
复制代码
2、索引的获取,并判断其是否存在
  1.     public void IndexIsExists() throws IOException {
  2.    
  3.     GetIndexRequest request = new GetIndexRequest("test6");
  4.    
  5.     boolean exists = restHighLevelClient.indices().exists(request,RequestOptions.DEFAULT);
  6.    
  7.     System.out.println(exists);
  8.    
  9.     restHighLevelClient.close();
  10.    
  11.     return;
  12.     }
复制代码
3、索引的删除
  1.     public void DeleteIndex() throws IOException {
  2.    
  3.     DeleteIndexRequest request = new DeleteIndexRequest("test6");
  4.    
  5.     AcknowledgedResponse response = restHighLevelClient.indices().delete(request,RequestOptions.DEFAULT);
  6.    
  7.     System.out.println(response.isAcknowledged());
  8.    
  9.     restHighLevelClient.close();
  10.    
  11.     return;
  12.     }
复制代码
文档的操作

1、文档的添加
  1.         public void AddDocument() throws IOException {
  2.                 User user = new User("笑笑",25);
  3.                 IndexRequest request = new IndexRequest("test");
  4.                 request.id("16");
  5.                 request.timeout(TimeValue.timeValueMillis(1000));
  6.                 request.source(JSON.toJSONString(user),XContentType.JSON);
  7.                 IndexResponse response = restHighLevelClient.index(request,RequestOptions.DEFAULT);
  8.                 System.out.println(response.status());
  9.                 System.out.println(response);
  10.                 restHighLevelClient.close();
  11.             return;
  12.         }
复制代码
2、文档信息的获取
  1.         public void GetDocument() throws IOException {
  2.                 GetRequest request = new GetRequest("test","1");
  3.                 GetResponse response = restHighLevelClient.get(request,RequestOptions.DEFAULT);
  4.                 System.out.println(response.getSourceAsString());
  5.                 restHighLevelClient.close();
  6.                 return;
  7.         }
复制代码
3、文档的获取,并判断其是否存在
  1.         public void DocumentIsExists() throws IOException {
  2.             GetRequest request = new GetRequest("test","1111");
  3.             request.fetchSourceContext(new FetchSourceContext(false));
  4.             request.storedFields("_none_");
  5.             boolean exists = restHighLevelClient.exists(request,RequestOptions.DEFAULT);
  6.             System.out.println(exists);
  7.             restHighLevelClient.close();
  8.             return;
  9.         }
复制代码
4、文档的更新
  1.         public void UpdateDocument() throws IOException {
  2.                 UpdateRequest request =  new UpdateRequest("test","16");
  3.                 User user = new User("黑黑",18);
  4.                 request.doc(JSON.toJSONString(user),XContentType.JSON);
  5.                 UpdateResponse response = restHighLevelClient.update(request,RequestOptions.DEFAULT);
  6.                 System.out.println(response.status());
  7.                 restHighLevelClient.close();
  8.             return;
  9.         }
复制代码
5、文档的删除
  1.         public void DeleteDocument() throws Exception {
  2.                 DeleteRequest request = new DeleteRequest("test","1");
  3.                 request.timeout("1s");
  4.                 DeleteResponse response = restHighLevelClient.delete(request,RequestOptions.DEFAULT);
  5.                 System.out.println(response.status());
  6.                 restHighLevelClient.close();
  7.         }
复制代码
6、文档的查询
  1.         public void Search() throws Exception {
  2.                 SearchRequest request = new SearchRequest("test");
  3.                 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  4.                 TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("name","明");
  5. //                MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
  6.                 searchSourceBuilder.highlighter(new HighlightBuilder());
  7.                 searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
  8.                 searchSourceBuilder.query(termQueryBuilder);
  9. //                searchSourceBuilder.query(matchAllQueryBuilder);
  10.                 searchSourceBuilder.from(0);
  11.                 searchSourceBuilder.size(100);
  12.                 request.source(searchSourceBuilder);
  13.                 SearchResponse search = restHighLevelClient.search(request, RequestOptions.DEFAULT);
  14.                 SearchHits hits = search.getHits();
  15.                 System.out.println(JSON.toJSONString(hits));
  16.                 System.out.println("++++++++++++++++++++++++++++++++++++++++");
  17.                 for (SearchHit documentFields: hits.getHits()) {
  18.                         System.out.println(documentFields.getSourceAsMap());
  19.                 }
  20.                 restHighLevelClient.close();
  21.         }
复制代码
错误的批量添加数据
  1.         public void test() throws Exception {
  2.             IndexRequest request = new IndexRequest("bulk");
  3.             request.source(JSON.toJSONString(new User("小1",12)),XContentType.JSON);
  4.                 request.source(JSON.toJSONString(new User("小2",12)),XContentType.JSON);
  5.                 request.source(JSON.toJSONString(new User("小3",12)),XContentType.JSON);
  6.                 request.source(JSON.toJSONString(new User("小4",12)),XContentType.JSON);
  7.                 request.source(JSON.toJSONString(new User("小5",12)),XContentType.JSON);
  8.                 request.source(JSON.toJSONString(new User("小6",12)),XContentType.JSON);
  9.                 request.source(JSON.toJSONString(new User("小7",12)),XContentType.JSON);
  10.                 IndexResponse indexResponse = restHighLevelClient.index(request,RequestOptions.DEFAULT);
  11.                 System.out.println(indexResponse.status());
  12.                 restHighLevelClient.close();
  13.         }
复制代码
7、批量添加数据
  1.         public void testBullk() throws Exception {
  2.                 BulkRequest bulkRequest = new BulkRequest();
  3.                 bulkRequest.timeout("10s");
  4.                 ArrayList<User> users = new ArrayList<>();
  5.                 users.add(new User("小1",12));
  6.                 users.add(new User("小2",12));
  7.                 users.add(new User("小3",12));
  8.                 users.add(new User("小4",12));
  9.                 users.add(new User("小5",12));
  10.                 users.add(new User("小6",12));
  11.                 for (User user:users) {
  12.                         bulkRequest.add(new IndexRequest("bulk").source(JSON.toJSONString(user),XContentType.JSON));
  13.                 }
  14.                 BulkResponse response = restHighLevelClient.bulk(bulkRequest,RequestOptions.DEFAULT);
  15.                 System.out.println(response.status());
  16.                 restHighLevelClient.close();
  17.         }
复制代码
七、ElasticSearch实战

防京东商城搜索(高亮)


1、导入依赖
  1.    
  2.         
  3.         org.jsoup   
  4.     jsoup   
  5.     1.10.2   
  6.         
  7.         com.alibaba   
  8.     fastjson   
  9.     1.2.70   
  10.         <dependency>   
  11.     <groupId>org.springframework.boot</groupId>   
  12.     <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  13. </dependency>   
  14.         
  15.         org.springframework.boot   
  16.     spring-boot-starter-thymeleaf   
  17.         
  18.         org.springframework.boot   
  19.     spring-boot-starter-web   
  20.         
  21.         org.springframework.boot   
  22.     spring-boot-devtools   
  23.     runtime   
  24.     true   
  25.         
  26.         org.springframework.boot   
  27.     spring-boot-configuration-processor   
  28.     true   
  29.         
  30.         org.projectlombok   
  31.     lombok   
  32.     true   
  33.         
  34.         org.springframework.boot   
  35.     spring-boot-starter-test   
  36.     test   
复制代码
2、导入前端素材
  1. ES资料地址:链接:https://pan.baidu.com/s/1qdvSk7SdVnlI8QzeK5gxaA
  2. 提取码:ldrh
复制代码
3、编写 application.preperties配置文件
  1. # 更改端口,防止冲突
  2. server.port=9999
  3. # 关闭thymeleaf缓存
  4. spring.thymeleaf.cache=false
复制代码
4、测试controller和view
  1. @Controller
  2. public class DemoApi {
  3.         @GetMapping({"/","index"})
  4.         public String index(){
  5.                 return "index";
  6.         }
  7. }
复制代码
5、编写service

ContentService
  1. @Service
  2. public class ContentService {
  3.         @Autowired
  4.         private RestHighLevelClient restHighLevelClient;
  5.         // 1、解析数据放入 es 索引中
  6.         public Boolean parseContent(String keyword) throws IOException {
  7.                 // 获取内容
  8.                 List<Content> contents = HtmlParseUtil.parseJD(keyword);
  9.                 // 内容放入 es 中
  10.                 BulkRequest bulkRequest = new BulkRequest();
  11.                 bulkRequest.timeout("2m"); // 可更具实际业务是指
  12.                 for (int i = 0; i < contents.size(); i++) {
  13.                         bulkRequest.add(
  14.                                         new IndexRequest("jd_goods")
  15.                                                         .id(""+(i+1))
  16.                                                         .source(JSON.toJSONString(contents.get(i)), XContentType.JSON)
  17.                         );
  18.                 }
  19.                 BulkResponse bulk = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
  20. //                restHighLevelClient.close();
  21.                 return !bulk.hasFailures();
  22.         }
  23.         // 2、根据keyword分页查询结果
  24.         public List<Map<String, Object>> search(String keyword, Integer pageIndex, Integer pageSize) throws IOException {
  25.                 if (pageIndex < 0){
  26.                         pageIndex = 0;
  27.                 }
  28.                 SearchRequest jd_goods = new SearchRequest("jd_goods");
  29.                 // 创建搜索源建造者对象
  30.                 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  31.                 // 条件采用:精确查询 通过keyword查字段name
  32.                 TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("name", keyword);
  33.                 searchSourceBuilder.query(termQueryBuilder);
  34.                 searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));// 60s
  35.                 // 分页
  36.                 searchSourceBuilder.from(pageIndex);
  37.                 searchSourceBuilder.size(pageSize);
  38.                 // 高亮
  39.                 // ....
  40.                 // 搜索源放入搜索请求中
  41.                 jd_goods.source(searchSourceBuilder);
  42.                 // 执行查询,返回结果
  43.                 SearchResponse searchResponse = restHighLevelClient.search(jd_goods, RequestOptions.DEFAULT);
  44. //                restHighLevelClient.close();
  45.                 // 解析结果
  46.                 SearchHits hits = searchResponse.getHits();
  47.                 List<Map<String,Object>> results = new ArrayList<>();
  48.                 for (SearchHit documentFields : hits.getHits()) {
  49.                         Map<String, Object> sourceAsMap = documentFields.getSourceAsMap();
  50.                         results.add(sourceAsMap);
  51.                 }
  52.                 // 返回查询的结果
  53.                 return results;
  54.         }
  55.         // 3、 在2的基础上进行高亮查询
  56.         public List<Map<String, Object>> highlightSearch(String keyword, Integer pageIndex, Integer pageSize) throws IOException {
  57.                 SearchRequest searchRequest = new SearchRequest("jd_goods");
  58.                 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  59.                 // 精确查询,添加查询条件
  60.                 TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("name", keyword);
  61.                 searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
  62.                 searchSourceBuilder.query(termQueryBuilder);
  63.                 // 分页
  64.                 searchSourceBuilder.from(pageIndex);
  65.                 searchSourceBuilder.size(pageSize);
  66.                 // 高亮 =========
  67.                 HighlightBuilder highlightBuilder = new HighlightBuilder();
  68.                 highlightBuilder.field("name");
  69.                 highlightBuilder.preTags("");
  70.                 highlightBuilder.postTags("");
  71.                 searchSourceBuilder.highlighter(highlightBuilder);
  72.                 // 执行查询
  73.                 searchRequest.source(searchSourceBuilder);
  74.                 SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
  75.                 // 解析结果 ==========
  76.                 SearchHits hits = searchResponse.getHits();
  77.                 List<Map<String, Object>> results = new ArrayList<>();
  78.                 for (SearchHit documentFields : hits.getHits()) {
  79.                         // 使用新的字段值(高亮),覆盖旧的字段值
  80.                         Map<String, Object> sourceAsMap = documentFields.getSourceAsMap();
  81.                         // 高亮字段
  82.                         Map<String, HighlightField> highlightFields = documentFields.getHighlightFields();
  83.                         HighlightField name = highlightFields.get("name");
  84.                         // 替换
  85.                         if (name != null){
  86.                                 Text[] fragments = name.fragments();
  87.                                 StringBuilder new_name = new StringBuilder();
  88.                                 for (Text text : fragments) {
  89.                                         new_name.append(text);
  90.                                 }
  91.                                 sourceAsMap.put("name",new_name.toString());
  92.                         }
  93.                         results.add(sourceAsMap);
  94.                 }
  95.                 return results;
  96.         }
  97. }
复制代码
6、编写controller
  1. @Controller
  2. public class DemoApi {
  3.         @GetMapping({"/","index"})
  4.         public String index(){
  5.                 return "index";
  6.         }
  7.         @Autowired
  8.         private ContentService contentService;
  9.         @ResponseBody
  10.         @GetMapping("/parse/{keyword}")
  11.         public Boolean parse(@PathVariable("keyword") String keyword) throws IOException {
  12.                 return contentService.parseContent(keyword);
  13.         }
  14.         @ResponseBody
  15.         @GetMapping("/search/{keyword}/{pageIndex}/{pageSize}")
  16.         public List<Map<String, Object>> parse(@PathVariable("keyword") String keyword,
  17.                                                                                    @PathVariable("pageIndex") Integer pageIndex,
  18.                                                                                    @PathVariable("pageSize") Integer pageSize) throws IOException {
  19.                 return contentService.search(keyword,pageIndex,pageSize);
  20.         }
  21.         @ResponseBody
  22.         @GetMapping("/h_search/{keyword}/{pageIndex}/{pageSize}")
  23.         public List<Map<String, Object>> highlightParse(@PathVariable("keyword") String keyword,
  24.                                                                                                         @PathVariable("pageIndex") Integer pageIndex,
  25.                                                                                                         @PathVariable("pageSize") Integer pageSize) throws IOException {
  26.                 return contentService.highlightSearch(keyword,pageIndex,pageSize);
  27.         }
  28. }
复制代码
7、爬虫(jsoup)

HtmlParseUtil
  1. public class HtmlParseUtil {
  2.         public static void main(String[] args) throws IOException {
  3.                 /// 使用前需要联网
  4.                 // 请求url
  5.                 String url = "http://search.jd.com/search?keyword=java";
  6.                 // 1.解析网页(jsoup 解析返回的对象是浏览器Document对象)
  7.                 Document document = Jsoup.parse(new URL(url), 30000);
  8.                 // 使用document可以使用在js对document的所有操作
  9.                 // 2.获取元素(通过id)
  10.                 Element j_goodsList = document.getElementById("J_goodsList");
  11.                 // 3.获取J_goodsList ul 每一个 li
  12.                 Elements lis = j_goodsList.getElementsByTag("li");
  13.                 // 4.获取li下的 img、price、name
  14.                 for (Element li : lis) {
  15.                         String img = li.getElementsByTag("img").eq(0).attr("src");// 获取li下 第一张图片
  16.                         String name = li.getElementsByClass("p-name").eq(0).text();
  17.                         String price = li.getElementsByClass("p-price").eq(0).text();
  18.                         System.out.println("=======================");
  19.                         System.out.println("img : " + img);
  20.                         System.out.println("name : " + name);
  21.                         System.out.println("price : " + price);
  22.                 }
  23.         }
  24.         public static List<Content> parseJD(String keyword) throws IOException {
  25.                 /// 使用前需要联网
  26.                 // 请求url
  27.                 String url = "http://search.jd.com/search?keyword=" + keyword;
  28.                 // 1.解析网页(jsoup 解析返回的对象是浏览器Document对象)
  29.                 Document document = Jsoup.parse(new URL(url), 30000);
  30.                 // 使用document可以使用在js对document的所有操作
  31.                 // 2.获取元素(通过id)
  32.                 Element j_goodsList = document.getElementById("J_goodsList");
  33.                 // 3.获取J_goodsList ul 每一个 li
  34.                 Elements lis = j_goodsList.getElementsByTag("li");
  35. //   
  36.     System.out.println(lis);
  37.                 // 4.获取li下的 img、price、name
  38.                 // list存储所有li下的内容
  39.                 List<Content> contents = new ArrayList<Content>();
  40.                 for (Element li : lis) {
  41.                         // 由于网站图片使用懒加载,将src属性替换为data-lazy-img
  42.                         String img = li.getElementsByTag("img").eq(0).attr("data-lazy-img");// 获取li下 第一张图片
  43.                         String name = li.getElementsByClass("p-name").eq(0).text();
  44.                         String price = li.getElementsByClass("p-price").eq(0).text();
  45.                         // 封装为对象
  46.                         Content content = new Content(name,img,price);
  47.                         // 添加到list中
  48.                         contents.add(content);
  49.                 }
  50.    
  51.     System.out.println(contents);
  52.                 // 5.返回 list
  53.                 return contents;
  54.         }
  55. }
复制代码
Content
  1. @Data
  2. @AllArgsConstructor
  3. @NoArgsConstructor
  4. public class Content implements Serializable {
  5.         private static final long serialVersionUID = -8049497962627482693L;
  6.         private String name;
  7.         private String img;
  8.         private String price;
  9. }
复制代码
8、前后端分离

引入js
  1.    
  2.    
复制代码
修改后的index.html
  1.    
  2.     狂神说Java-ES仿京东实战   
  3.         
  4.         
  5.         
  6.         
  7.         
  8.         
  9.         
  10.         
  11.         
  12.         
  13.         
  14.     [size=6]   
  15.         
  16.         
  17.     [img]http://dis.qidao123.com/@{/images/jdlogo.png}[/img]   
  18.         
  19.         [/size]
  20.    
  21.         
  22.         
  23.         
  24.         
  25.         
  26.         
  27.         
  28.         
  29.         
  30.         
  31.         
  32.         
  33.         
  34.         
  35.         
  36.         
  37.         
  38.         
  39.         
  40.         天猫搜索   
  41.         
  42.         
  43.         
  44.         
  45.         
  46.         
  47.         
  48.         
  49.         
  50.         
  51.         
  52.         
  53.         
  54.         
  55.         
  56.         
  57.         
  58.         
  59.         
  60.         
  61.         
  62.         
  63.         
  64.         
  65.         
  66.         
  67.         
  68.         
  69.         
  70.         
  71.         
  72.         
  73.         
  74.         
  75.         
  76.         搜索   
  77.         
  78.         
  79.         
  80.         
  81.         
  82.         
  83.         
  84.         
  85.         
  86.         
  87.         
  88.         
  89.         
  90.         
  91.         
  92. [list]   
  93.         
  94.         
  95.         
  96.    
  97. [*][url=http://dis.qidao123.com/]狂神说Java[/url]   
  98.         
  99.         
  100.         
  101.    
  102. [*][url=http://dis.qidao123.com/]狂神说前端[/url]   
  103.         
  104.         
  105.         
  106.    
  107. [*][url=http://dis.qidao123.com/]狂神说Linux[/url]   
  108.         
  109.         
  110.         
  111.    
  112. [*][url=http://dis.qidao123.com/]狂神说大数据[/url]   
  113.         
  114.         
  115.         
  116.    
  117. [*][url=http://dis.qidao123.com/]狂神聊理财[/url]   
  118.         
  119.         
  120.         
  121. [/list]   
  122.         
  123.         
  124.         
  125.         
  126.         
  127.         
  128.         
  129.         
  130.         
  131.         
  132.         
  133.         
  134.         
  135.         
  136.         
  137.         
  138.         
  139.         
  140.         
  141.         
  142.         
  143.         
  144.         
  145.         
  146.         
  147.         
  148.         
  149.         
  150.         
  151.         
  152.         
  153.         
  154.         
  155.         
  156.     品牌   
  157.         
  158.         
  159.         
  160.         
  161.         
  162.         
  163.         
  164.         
  165.         
  166.         
  167.         
  168.         
  169. [list]   
  170.         
  171.         
  172.         
  173.         
  174.    
  175. [*][url=https://www.cnblogs.com/#]狂神说[/url]   
  176.         
  177.         
  178.         
  179.         
  180.    
  181. [*][url=https://www.cnblogs.com/#]Java[/url]   
  182.         
  183.         
  184.         
  185.         
  186. [/list]   
  187.         
  188.         
  189.         
  190.         
  191.         
  192.         
  193.         
  194.         
  195.         
  196.         
  197.         
  198.         
  199.         
  200.         
  201.         
  202.         
  203.         
  204.         
  205.         
  206.         
  207.         [url=http://dis.qidao123.com/]综合[/url]   
  208.         
  209.         [url=http://dis.qidao123.com/]人气[/url]   
  210.         
  211.         [url=http://dis.qidao123.com/]新品[/url]   
  212.         
  213.         [url=http://dis.qidao123.com/]销量[/url]   
  214.         
  215.         [url=http://dis.qidao123.com/]价格[/url]   
  216.         
  217.         
  218.         
  219.         
  220.         
  221.         
  222.         
  223.         
  224.         
  225.         
  226.         
  227.         
  228.         
  229.         
  230.         
  231.         
  232.         
  233.         
  234.         
  235.         
  236.         
  237.         [url=http://dis.qidao123.com/][img]http://dis.qidao123.com/result.img[/img][/url]   
  238.         
  239.         
  240.         
  241.         
  242.         
  243.         
  244.         
  245.         
  246.         
  247.         
  248.         
  249.         
  250.         
  251.         
  252.         
  253.         
  254.         
  255.    
  256.    
  257.         
  258.         
  259.         
  260.         
  261.         
  262.         
  263.         
  264.         
  265.         
  266.         
  267.         
  268.         
  269.         
  270.         
  271.    
  272.         
  273.         
  274.         
  275.         
  276.         
  277.         
  278.         
  279.         
  280.         
  281.         
  282.     店铺: 狂神说Java   
  283.         
  284.         
  285.         
  286.         
  287.         
  288.         
  289.         
  290.         
  291.         
  292.         
  293.         
  294.         
  295.         
  296.          月成交[i]999笔[/i]   
  297.         
  298.         
  299.         
  300.     评价 [url=http://dis.qidao123.com/]3[/url]   
  301.         
  302.         
  303.         
  304.    
  305.         
  306.         
  307.         
  308.         
  309.         
  310.         
  311.         
  312.         
  313.         
  314.         
复制代码
9、遗留问题
  1. restHighLevelClient.close(); 引起java.lang.RuntimeException: Request execution cancelled 错误
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

惊落一身雪

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表