一 介绍:

  ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。

  ElasticSearch 是一个分布式、高扩展、高实时的搜索与数据分析引擎。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用ElasticSearch的水平伸缩性,能使数据在生产环境变得更有价值。  

  ElasticSearch 的实现原理主要分为以下几个步骤,首先用户将数据提交到Elastic Search 数据库中,再通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据,当用户搜索数据时候,再根据权重将结果排名,打分,再将返回结果呈现给用户。

  Elasticsearch是与名为Logstash的数据收集和日志解析引擎以及名为Kibana的分析和可视化平台一起开发的。这三个产品被设计成一个集成解决方案,称为“Elastic Stack”(以前称为“ELK stack”)。
  Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。”Elasticsearch是分布式的,这意味着索引可以被分成分片,每个分片可以有0个或多个副本。每个节点托管一个或多个分片,并充当协调器将操作委托给正确的分片。再平衡和路由是自动完成的。“相关数据通常存储在同一个索引中,该索引由一个或多个主分片和零个或多个复制分片组成。一旦创建了索引,就不能更改主分片的数量。
  Elasticsearch使用Lucene,并试图通过JSON和Java API提供其所有特性。它支持facetting和percolating,如果新文档与注册查询匹配,这对于通知非常有用。另一个特性称为“网关”,处理索引的长期持久性;例如,在服务器崩溃的情况下,可以从网关恢复索引。Elasticsearch支持实时GET请求,适合作为NoSQL数据存储,但缺少分布式事务
 
  es在系统中常用地位:
  

  总结:

    1、elasticsearch是一个基于Lucene的高扩展的分布式搜索服务器,支持开箱即用。

    2、elasticsearch隐藏了Lucene的复杂性,对外提供Restful 接口来操作索引、搜索。

  突出优点:

    1. 扩展性好,可部署上百台服务器集群,处理PB级数据。

    2.近实时的去索引数据、搜索数据。

  es和solr选择哪个?

    1.如果你公司现在用的solr可以满足需求就不要换了。

    2.如果你公司准备进行全文检索项目的开发,建议优先考虑elasticsearch,因为像Github这样大规模的搜索都在用

二 elasticsearch概念介绍

  1 cluster:

    代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的。es的一个概念就是去中心化,字面上理解就是无中心节点,这是对于集群外部来说的,因为从外部来看es集群,在逻辑上是个整体,你与任何一个节点的通信和与整个es集群通信是等价的。

  2 shards:
    代表索引分片,es可以把一个完整的索引分成多个分片,这样的好处是可以把一个大的索引拆分成多个,分布到不同的节点上。构成分布式搜索。分片的数量只能在索引创建前指定,并且索引创建后不能更改。
  3 replicas:
    代表索引副本,es可以设置多个索引的副本,副本的作用一是提高系统的容错性,当某个节点某个分片损坏或丢失时可以从副本中恢复。二是提高es的查询效率,es会自动对搜索请求进行负载均衡。
  4 recovery:
    代表数据恢复或叫数据重新分布,es在有节点加入或退出时会根据机器的负载对索引分片进行重新分配,挂掉的节点重新启动时也会进行数据恢复。
river:代表es的一个数据源,也是其它存储方式(如:数据库)同步数据到es的一个方法。它是以插件方式存在的一个es服务,通过读取river中的数据并把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的。
  5 gateway:
    代表es索引快照的存储方式,es默认是先把索引存放到内存中,当内存满了时再持久化到本地硬盘。gateway对索引快照进行存储,当这个es集群关闭再重新启动时就会从gateway中读取索引备份数据。es支持多种类型的gateway,有本地文件系统(默认),分布式文件系统,Hadoop的HDFS和amazon的s3云存储服务。
  6 discovery.zen:
    代表es的自动发现节点机制,es是一个基于p2p的系统,它先通过广播寻找存在的节点,再通过多播协议来进行节点之间的通信,同时也支持点对点的交互。
  7 Transport:
    代表es内部节点或集群与客户端的交互方式,默认内部是使用tcp协议进行交互,同时它支持http协议(json格式)、thrift、servlet、memcached、zeroMQ等的传输协议(通过插件方式集成)。  
  8 映射(Mapping);

    映射是用于定义ES对索引中字段的存储类型、分词方式和是否存储等信息,就像数据库中的 schema ,描述了文档可能具有的字段或属性、每个字段的数据类型。只不过关系型数据库建表时必须指定字段类型,而ES对于字段类型可以不指定然后动态对字段类型猜测,也可以在创建索引时具体指定字段的类型。

    对字段类型根据数据格式自动识别的映射称之为动态映射(Dynamic mapping),我们创建索引时具体定义字段类型的映射称之为静态映射或显示映射(Explicit mapping)

 
    简单而言之,就是相当于关系型数据库的字段关系
  9 type
    相当于关系型数据的表,在6.0之后逐步废弃
总结:

  在索引中每个文档都包括了一个或多个field,创建映射就是向索引库中创建field的过程,下边是document和field

  与关系数据库的概念的类比:

    文档(Document)----------------Row记录

    字段(Field)-------------------Columns 列

  注意:6.0之前的版本有type(类型)概念,type相当于关系数据库的表,ES官方将在ES9.0版本中彻底删除type。

  上边讲的创建索引库相当于关系数据库中的数据库还是表?

    1、如果相当于数据库就表示一个索引库可以创建很多不同类型的文档,这在ES中也是允许的。

    2、如果相当于表就表示一个索引库只能存储相同类型的文档,ES官方建议 在一个索引库中只存储相同类型的文档

三 安装使用:
  

  安装配置:

    1、新版本要求至少jdk1.8以上。

    2、支持tar、zip、rpm等多种安装方式。

  在windows下开发建议使用ZIP安装方式。

  3、支持docker方式安装

    详细参见:https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

    下载 ES: Elasticsearch 6.2.1

    https://www.elastic.co/downloads/past-releases

    解压 elasticsearch-6.2.1.zip

  解压之后截图:

    

    bin:脚本目录,包括:启动、停止等可执行脚本

    config:配置文件目录

    data:索引目录,存放索引文件的地方

    logs:日志目录

    modules:模块目录,包括了es的功能模块

    plugins :插件目录,es支持插件机制

  配置文件详解:

    

    elasticsearch.yml : 用于配置Elasticsearch运行参数

    jvm.options : 用于配置Elasticsearch JVM设置

    log4j2.properties: 用于配置Elasticsearch日志

      elasticsearch.yml 配置: 我的配置:

    

  1. # ======================== Elasticsearch Configuration =========================
  2. #
  3. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4. # Before you set out to tweak and tune the configuration, make sure you
  5. # understand what are you trying to accomplish and the consequences.
  6. #
  7. # The primary way of configuring a node is via this file. This template lists
  8. # the most important settings you may want to configure for a production cluster.
  9. #
  10. # Please consult the documentation for further information on configuration options:
  11. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  12. #
  13. # ---------------------------------- Cluster -----------------------------------
  14. #
  15. # Use a descriptive name for your cluster:
  16. #
  17. #cluster.name: my-application
  18. #
  19. # ------------------------------------ Node ------------------------------------
  20. #
  21. # Use a descriptive name for the node:
  22. #
  23. #node.name: node-
  24. #
  25. # Add custom attributes to the node:
  26. #
  27. #node.attr.rack: r1
  28. #
  29. # ----------------------------------- Paths ------------------------------------
  30. #
  31. # Path to directory where to store the data (separate multiple locations by comma):
  32. #
  33. #path.data: /path/to/data
  34. #
  35. # Path to log files:
  36. #
  37. #path.logs: /path/to/logs
  38. #
  39. # ----------------------------------- Memory -----------------------------------
  40. #
  41. # Lock the memory on startup:
  42. #
  43. #bootstrap.memory_lock: true
  44. #
  45. # Make sure that the heap size is set to about half the memory available
  46. # on the system and that the owner of the process is allowed to use this
  47. # limit.
  48. #
  49. # Elasticsearch performs poorly when the system is swapping the memory.
  50. #
  51. # ---------------------------------- Network -----------------------------------
  52. #
  53. # Set the bind address to a specific IP (IPv4 or IPv6):
  54. #
  55. #network.host: 192.168.0.1
  56. #
  57. # Set a custom port for HTTP:
  58. #
  59. #http.port:
  60. #
  61. # For more information, consult the network module documentation.
  62. #
  63. # --------------------------------- Discovery ----------------------------------
  64. #
  65. # Pass an initial list of hosts to perform discovery when new node is started:
  66. # The default list of hosts is ["127.0.0.1", "[::1]"]
  67. #
  68. #discovery.zen.ping.unicast.hosts: ["host1", "host2"]
  69. #
  70. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / + ):
  71. #
  72. #discovery.zen.minimum_master_nodes:
  73. #
  74. # For more information, consult the zen discovery module documentation.
  75. #
  76. # ---------------------------------- Gateway -----------------------------------
  77. #
  78. # Block initial recovery after a full cluster restart until N nodes are started:
  79. #
  80. #gateway.recover_after_nodes:
  81. #
  82. # For more information, consult the gateway module documentation.
  83. #
  84. # ---------------------------------- Various -----------------------------------
  85. #
  86. # Require explicit names when deleting indices:
  87. #
  88. #action.destructive_requires_name: true
  89.  
  90. cluster.name: cxy
  91. node.name: cxy_node_1
  92. network.host: 0.0.0.0
  93. http.port:
  94. transport.tcp.port:
  95. node.master: true
  96. node.data: true
  97. discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]
  98. discovery.zen.minimum_master_nodes:
  99. node.ingest: true
  100. bootstrap.memory_lock: false
  101. node.max_local_storage_nodes:
  102.  
  103. path.data: D:\javafuwu\elasticsearch\elasticsearch-6.2.\data
  104. path.logs: D:\javafuwu\elasticsearch\elasticsearch-6.2.\logs
  105.  
  106. http.cors.enabled: true
  107. http.cors.allow-origin: /.*/

jvm配置:

  1. ## JVM configuration
  2.  
  3. ################################################################
  4. ## IMPORTANT: JVM heap size
  5. ################################################################
  6. ##
  7. ## You should always set the min and max JVM heap
  8. ## size to the same value. For example, to set
  9. ## the heap to GB, set:
  10. ##
  11. ## -Xms4g
  12. ## -Xmx4g
  13. ##
  14. ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
  15. ## for more information
  16. ##
  17. ################################################################
  18.  
  19. # Xms represents the initial size of total heap space
  20. # Xmx represents the maximum size of total heap space
  21.  
  22. -Xms1g
  23. -Xmx1g
  24.  
  25. ################################################################
  26. ## Expert settings
  27. ################################################################
  28. ##
  29. ## All settings below this section are considered
  30. ## expert settings. Don't tamper with them unless
  31. ## you understand what you are doing
  32. ##
  33. ################################################################
  34.  
  35. ## GC configuration
  36. -XX:+UseConcMarkSweepGC
  37. -XX:CMSInitiatingOccupancyFraction=
  38. -XX:+UseCMSInitiatingOccupancyOnly
  39.  
  40. ## optimizations
  41.  
  42. # pre-touch memory pages used by the JVM during initialization
  43. -XX:+AlwaysPreTouch
  44.  
  45. ## basic
  46.  
  47. # explicitly set the stack size
  48. -Xss1m
  49.  
  50. # set to headless, just in case
  51. -Djava.awt.headless=true
  52.  
  53. # ensure UTF- encoding by default (e.g. filenames)
  54. -Dfile.encoding=UTF-
  55.  
  56. # use our provided JNA always versus the system one
  57. -Djna.nosys=true
  58.  
  59. # turn off a JDK optimization that throws away stack traces for common
  60. # exceptions because stack traces are important for debugging
  61. -XX:-OmitStackTraceInFastThrow
  62.  
  63. # flags to configure Netty
  64. -Dio.netty.noUnsafe=true
  65. -Dio.netty.noKeySetOptimization=true
  66. -Dio.netty.recycler.maxCapacityPerThread=
  67.  
  68. # log4j
  69. -Dlog4j.shutdownHookEnabled=false
  70. -Dlog4j2.disable.jmx=true
  71.  
  72. -Djava.io.tmpdir=${ES_TMPDIR}
  73.  
  74. ## heap dumps
  75.  
  76. # generate a heap dump when an allocation from the Java heap fails
  77. # heap dumps are created in the working directory of the JVM
  78. -XX:+HeapDumpOnOutOfMemoryError
  79.  
  80. # specify an alternative path for heap dumps
  81. # ensure the directory exists and has sufficient space
  82. #-XX:HeapDumpPath=/heap/dump/path
  83.  
  84. ## JDK GC logging
  85.  
  86. :-XX:+PrintGCDetails
  87. :-XX:+PrintGCDateStamps
  88. :-XX:+PrintTenuringDistribution
  89. :-XX:+PrintGCApplicationStoppedTime
  90. :-Xloggc:logs/gc.log
  91. :-XX:+UseGCLogFileRotation
  92. :-XX:NumberOfGCLogFiles=
  93. :-XX:GCLogFileSize=64m
  94.  
  95. # JDK + GC logging
  96. -:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=,filesize=64m
  97. # due to internationalization enhancements in JDK Elasticsearch need to set the provider to COMPAT otherwise
  98. # time/date parsing will break in an incompatible way for some date patterns and locals
  99. -:-Djava.locale.providers=COMPAT

日志配置:

  1. status = error
  2.  
  3. # log action execution errors for easier debugging
  4. logger.action.name = org.elasticsearch.action
  5. logger.action.level = debug
  6.  
  7. appender.console.type = Console
  8. appender.console.name = console
  9. appender.console.layout.type = PatternLayout
  10. appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{.}] %marker%m%n
  11.  
  12. appender.rolling.type = RollingFile
  13. appender.rolling.name = rolling
  14. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log
  15. appender.rolling.layout.type = PatternLayout
  16. appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{.}] %marker%.-10000m%n
  17. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz
  18. appender.rolling.policies.type = Policies
  19. appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
  20. appender.rolling.policies.time.interval =
  21. appender.rolling.policies.time.modulate = true
  22. appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
  23. appender.rolling.policies.size.size = 128MB
  24. appender.rolling.strategy.type = DefaultRolloverStrategy
  25. appender.rolling.strategy.fileIndex = nomax
  26. appender.rolling.strategy.action.type = Delete
  27. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
  28. appender.rolling.strategy.action.condition.type = IfFileName
  29. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-*
  30. appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize
  31. appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB
  32.  
  33. rootLogger.level = info
  34. rootLogger.appenderRef.console.ref = console
  35. rootLogger.appenderRef.rolling.ref = rolling
  36.  
  37. appender.deprecation_rolling.type = RollingFile
  38. appender.deprecation_rolling.name = deprecation_rolling
  39. appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log
  40. appender.deprecation_rolling.layout.type = PatternLayout
  41. appender.deprecation_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{.}] %marker%.-10000m%n
  42. appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.log.gz
  43. appender.deprecation_rolling.policies.type = Policies
  44. appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy
  45. appender.deprecation_rolling.policies.size.size = 1GB
  46. appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
  47. appender.deprecation_rolling.strategy.max =
  48.  
  49. logger.deprecation.name = org.elasticsearch.deprecation
  50. logger.deprecation.level = warn
  51. logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling
  52. logger.deprecation.additivity = false
  53.  
  54. appender.index_search_slowlog_rolling.type = RollingFile
  55. appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling
  56. appender.index_search_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog.log
  57. appender.index_search_slowlog_rolling.layout.type = PatternLayout
  58. appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.-10000m%n
  59. appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog-%d{yyyy-MM-dd}.log
  60. appender.index_search_slowlog_rolling.policies.type = Policies
  61. appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy
  62. appender.index_search_slowlog_rolling.policies.time.interval =
  63. appender.index_search_slowlog_rolling.policies.time.modulate = true
  64.  
  65. logger.index_search_slowlog_rolling.name = index.search.slowlog
  66. logger.index_search_slowlog_rolling.level = trace
  67. logger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = index_search_slowlog_rolling
  68. logger.index_search_slowlog_rolling.additivity = false
  69.  
  70. appender.index_indexing_slowlog_rolling.type = RollingFile
  71. appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling
  72. appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog.log
  73. appender.index_indexing_slowlog_rolling.layout.type = PatternLayout
  74. appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.-10000m%n
  75. appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog-%d{yyyy-MM-dd}.log
  76. appender.index_indexing_slowlog_rolling.policies.type = Policies
  77. appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy
  78. appender.index_indexing_slowlog_rolling.policies.time.interval =
  79. appender.index_indexing_slowlog_rolling.policies.time.modulate = true
  80.  
  81. logger.index_indexing_slowlog.name = index.indexing.slowlog.index
  82. logger.index_indexing_slowlog.level = trace
  83. logger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = index_indexing_slowlog_rolling
  84. logger.index_indexing_slowlog.additivity = false

注意在生产上配置不可以配置debug级别,

然后启动:

点击elasticsearch.bat就可以启动了:

然后在浏览器上输入:

localhost:9200就可以看到相关信息

  1. {
  2. "name" : "cxy_node_1",
  3. "cluster_name" : "cxy",
  4. "cluster_uuid" : "P38fyKScTreA8ptsvHe0PQ",
  5. "version" : {
  6. "number" : "6.2.1",
  7. "build_hash" : "7299dc3",
  8. "build_date" : "2018-02-07T19:34:26.990113Z",
  9. "build_snapshot" : false,
  10. "lucene_version" : "7.2.1",
  11. "minimum_wire_compatibility_version" : "5.6.0",
  12. "minimum_index_compatibility_version" : "5.0.0"
  13. },
  14. "tagline" : "You Know, for Search"
  15. }

有些地方大家是不是很熟悉,就是在配置文件中配置的集群名称

四 插件安装:  

  head插件是ES的一个可视化管理插件,用来监视ES的状态,并通过head客户端和ES服务进行交互,比如创建映

射、创建索引等,head的项目地址在https://github.com/mobz/elasticsearch-head  。

  从ES6.0开始,head插件支持使得node.js运行。

    1、安装node.js

    2、下载head并运行

    git clone git://github.com/mobz/elasticsearch-head.git

    cd elasticsearch-head

    npm install

    npm run start open

    HTTP://本地主机:9100 /

3、运行

可以看到相关结果:

五:创建索引和映射:

  使用postman工具:

    put   http://localhost:9200/chenxuyou     此处chenxuyou  是索引库的名称

      body里面丢进参数:参数和副本

      

  1. {
  2. "settings":{
  3. "index":{
  4. "number_of_shards":,
  5. "number_of_replicas":
  6. }
  7. }
  8. }

然后返回结果

  1. {
  2. "acknowledged": true,
  3. "shards_acknowledged": true,
  4. "index": "chenxuyou"
  5. }

创建映射:

  1. http://localhost:9200/chenxuyou1/doc/_mapping
  2.  
  3. {
  4. "properties":{
  5. "name":{
  6. "type":"text"
  7. },
  8. "description":{
  9. "type":"text"
  10. },
  11. "address":{
  12. "type":"keyword"
  13. }
  14. }
  15.  
  16. }
  17.  
  18. 结果:

{
"acknowledged": true
}

  1.  

然后将方法写get 就可以获取到刚才创建的信息

  1. http://localhost:9200/chenxuyou1/doc/_mapping get方法

结果:

  1. {
  2. "chenxuyou1": {
  3. "mappings": {
  4. "doc": {
  5. "properties": {
  6. "address": {
  7. "type": "keyword"
  8. },
  9. "description": {
  10. "type": "text"
  11. },
  12. "name": {
  13. "type": "text"
  14. }
  15. }
  16. }
  17. }
  18. }
  19. }

就可以将所有信息进行查询:

在这里创建更快

创建文档:

  1. http://localhost:9200/chenxuyou2/doc/4028e58161bcf7f40161bcf8b77c0000
  2.  
  3. {
  4. "name":"Bootstrap开发框架",
  5. "description":"Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开程序人员)轻松的实现一个不受浏览器限制的精美界面效果。",
  6. "address":""
  7.  
  8. }
  9.  
  10. {
  11. "_index": "chenxuyou2",
  12. "_type": "doc",
  13. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  14. "_version": ,
  15. "result": "created",
  16. "_shards": {
  17. "total": ,
  18. "successful": ,
  19. "failed":
  20. },
  21. "_seq_no": ,
  22. "_primary_term":
  23. }

查询文档:

  1. http://localhost:9200/chenxuyou2/doc/4028e58161bcf7f40161bcf8b77c0000
  2.  
  3. get请求
  4.  
  5. 结果:
  6. {
  7. "_index": "chenxuyou2",
  8. "_type": "doc",
  9. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  10. "_version": ,
  11. "found": true,
  12. "_source": {
  13. "name": "Bootstrap开发框架",
  14. "description": "Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开程序人员)轻松的实现一个不受浏览器限制的精美界面效果。",
  15. "address": ""
  16. }
  17. }

查询所有文档:

  1. http://localhost:9200/chenxuyou2/doc/_search
  2.  
  3. get
  4.  
  5. {
  6. "took": ,
  7. "timed_out": false,
  8. "_shards": {
  9. "total": ,
  10. "successful": ,
  11. "skipped": ,
  12. "failed":
  13. },
  14. "hits": {
  15. "total": ,
  16. "max_score": ,
  17. "hits": [
  18. {
  19. "_index": "chenxuyou2",
  20. "_type": "doc",
  21. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  22. "_score": ,
  23. "_source": {
  24. "name": "Bootstrap开发框架",
  25. "description": "Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开程序人员)轻松的实现一个不受浏览器限制的精美界面效果。",
  26. "address": ""
  27. }
  28. }
  29. ]
  30. }
  31. }

查询带关键字:

  1. http://localhost:9200/chenxuyou2/doc/_search?q=name:bootstrap
  2.  
  3. get
  4.  
  5. 结果:
  6.  
  7. {
  8. "took": ,
  9. "timed_out": false,
  10. "_shards": {
  11. "total": ,
  12. "successful": ,
  13. "skipped": ,
  14. "failed":
  15. },
  16. "hits": {
  17. "total": ,
  18. "max_score": 0.2876821,
  19. "hits": [
  20. {
  21. "_index": "chenxuyou2",
  22. "_type": "doc",
  23. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  24. "_score": 0.2876821,
  25. "_source": {
  26. "name": "Bootstrap开发框架",
  27. "description": "Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开程序人员)轻松的实现一个不受浏览器限制的精美界面效果。",
  28. "address": ""
  29. }
  30. }
  31. ]
  32. }
  33. }
 精确查询:
  1. http://localhost:9200/chenxuyou2/doc/_search?q=address:201001
  2.  
  3. get
  4.  
  5. 结果:
  1. {
  2. "took": ,
  3. "timed_out": false,
  4. "_shards": {
  5. "total": ,
  6. "successful": ,
  7. "skipped": ,
  8. "failed":
  9. },
  10. "hits": {
  11. "total": ,
  12. "max_score": 0.2876821,
  13. "hits": [
  14. {
  15. "_index": "chenxuyou2",
  16. "_type": "doc",
  17. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  18. "_score": 0.2876821,
  19. "_source": {
  20. "name": "Bootstrap开发框架",
  21. "description": "Bootstrap是由Twitter推出的一个前台页面开发框架,在行业之中使用较为广泛。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长页面开程序人员)轻松的实现一个不受浏览器限制的精美界面效果。",
  22. "address": ""
  23. }
  24. }
  25. ]
  26. }

查询不存在:

  1. http://localhost:9200/chenxuyou2/doc/_search?q=address:20100
  2.  
  3. get
  4.  
  5. {
  6. "took": ,
  7. "timed_out": false,
  8. "_shards": {
  9. "total": ,
  10. "successful": ,
  11. "skipped": ,
  12. "failed":
  13. },
  14. "hits": {
  15. "total": ,
  16. "max_score": null,
  17. "hits": []
  18. }
  19. }

查询结果内容的意思:

took:本次操作花费的时间,单位为毫秒。

timed_out:请求是否超时

_shards:说明本次操作共搜索了哪些分片

hits:搜索命中的记录

hits.total :符合条件的文档总数

hits.hits :匹配度较高的前N个文档

hits.max_score:文档匹配得分,这里为最高分

_score:每个文档都有一个匹配度得分,按照降序排列。

_source:显示了文档的原始内容。

六 ik分词器的使用:

首先为什么要使用ik分词器呢:

测试分词:

  1. localhost:/_analyze
  2.  
  3. post
  4.  
  5. body内容:
  6. {"text":"测试分词器,后边是测试内容"
  7.  
  8. }
  9.  
  10. 结果:
  11. {
  12. "tokens": [
  13. {
  14. "token": "测",
  15. "start_offset": ,
  16. "end_offset": ,
  17. "type": "<IDEOGRAPHIC>",
  18. "position":
  19. },
  20. {
  21. "token": "试",
  22. "start_offset": ,
  23. "end_offset": ,
  24. "type": "<IDEOGRAPHIC>",
  25. "position":
  26. },
  27. {
  28. "token": "分",
  29. "start_offset": ,
  30. "end_offset": ,
  31. "type": "<IDEOGRAPHIC>",
  32. "position":
  33. },
  34. {
  35. "token": "词",
  36. "start_offset": ,
  37. "end_offset": ,
  38. "type": "<IDEOGRAPHIC>",
  39. "position":
  40. },
  41. {
  42. "token": "器",
  43. "start_offset": ,
  44. "end_offset": ,
  45. "type": "<IDEOGRAPHIC>",
  46. "position":
  47. },
  48. {
  49. "token": "后",
  50. "start_offset": ,
  51. "end_offset": ,
  52. "type": "<IDEOGRAPHIC>",
  53. "position":
  54. },
  55. {
  56. "token": "边",
  57. "start_offset": ,
  58. "end_offset": ,
  59. "type": "<IDEOGRAPHIC>",
  60. "position":
  61. },
  62. {
  63. "token": "是",
  64. "start_offset": ,
  65. "end_offset": ,
  66. "type": "<IDEOGRAPHIC>",
  67. "position":
  68. },
  69. {
  70. "token": "测",
  71. "start_offset": ,
  72. "end_offset": ,
  73. "type": "<IDEOGRAPHIC>",
  74. "position":
  75. },
  76. {
  77. "token": "试",
  78. "start_offset": ,
  79. "end_offset": ,
  80. "type": "<IDEOGRAPHIC>",
  81. "position":
  82. },
  83. {
  84. "token": "内",
  85. "start_offset": ,
  86. "end_offset": ,
  87. "type": "<IDEOGRAPHIC>",
  88. "position":
  89. },
  90. {
  91. "token": "容",
  92. "start_offset": ,
  93. "end_offset": ,
  94. "type": "<IDEOGRAPHIC>",
  95. "position":
  96. }
  97. ]
  98. }

可以看到对中文的支持非常差,所以需要中文分词器来进行分词

使用IK分词器可以实现对中文分词的效果。 下载IK分词器:(Github地址:https://github.com/medcl/elasticsearch-analysis-ik)

首先解压ik分词器:

将这个目录拷贝到es的plgin目录下:

ik分词器的测试:

  1. localhost:/_analyze
  2.  
  3. {"text":"测试分词器,后边是测试内容",
  4. "analyzer":"ik_max_word"
  5.  
  6. }
  7.  
  8. 结果:
  9. {
  10. "tokens": [
  11. {
  12. "token": "测试",
  13. "start_offset": ,
  14. "end_offset": ,
  15. "type": "CN_WORD",
  16. "position":
  17. },
  18. {
  19. "token": "分词器",
  20. "start_offset": ,
  21. "end_offset": ,
  22. "type": "CN_WORD",
  23. "position":
  24. },
  25. {
  26. "token": "分词",
  27. "start_offset": ,
  28. "end_offset": ,
  29. "type": "CN_WORD",
  30. "position":
  31. },
  32. {
  33. "token": "器",
  34. "start_offset": ,
  35. "end_offset": ,
  36. "type": "CN_CHAR",
  37. "position":
  38. },
  39. {
  40. "token": "后边",
  41. "start_offset": ,
  42. "end_offset": ,
  43. "type": "CN_WORD",
  44. "position":
  45. },
  46. {
  47. "token": "是",
  48. "start_offset": ,
  49. "end_offset": ,
  50. "type": "CN_CHAR",
  51. "position":
  52. },
  53. {
  54. "token": "测试",
  55. "start_offset": ,
  56. "end_offset": ,
  57. "type": "CN_WORD",
  58. "position":
  59. },
  60. {
  61. "token": "内容",
  62. "start_offset": ,
  63. "end_offset": ,
  64. "type": "CN_WORD",
  65. "position":
  66. }
  67. ]
  68. }
  1. localhost:/_analyze
  2.  
  3. {"text":"测试分词器,后边是测试内容",
  4. "analyzer":"ik_smart"
  5.  
  6. }
  7.  
  8. 结果:
  9. {
  10. "tokens": [
  11. {
  12. "token": "测试",
  13. "start_offset": ,
  14. "end_offset": ,
  15. "type": "CN_WORD",
  16. "position":
  17. },
  18. {
  19. "token": "分词器",
  20. "start_offset": ,
  21. "end_offset": ,
  22. "type": "CN_WORD",
  23. "position":
  24. },
  25. {
  26. "token": "后边",
  27. "start_offset": ,
  28. "end_offset": ,
  29. "type": "CN_WORD",
  30. "position":
  31. },
  32. {
  33. "token": "是",
  34. "start_offset": ,
  35. "end_offset": ,
  36. "type": "CN_CHAR",
  37. "position":
  38. },
  39. {
  40. "token": "测试",
  41. "start_offset": ,
  42. "end_offset": ,
  43. "type": "CN_WORD",
  44. "position":
  45. },
  46. {
  47. "token": "内容",
  48. "start_offset": ,
  49. "end_offset": ,
  50. "type": "CN_WORD",
  51. "position":
  52. }
  53. ]
  54. }

上面是两种测试:

ik分词器有两种分词模式:ik_max_word和ik_smart模式。

1、ik_max_word 会将文本做最细粒度的拆分,比如会将“中华人民共和国人民大会堂”拆分为“中华人民共和国、中华人民、中华、 华人、人民共和国、人民、共和国、大会堂、大会、会堂等词语。

2、ik_smart 会做最粗粒度的拆分,比如会将“中华人民共和国人民大会堂”拆分为中华人民共和国、人民大会堂。

自定义ik分词器词库:

  原因:由于ik分词器只会将常用词库进行分词,那么有些词是不可以分的

再新建文件:

my.dic

内容:

陈秀峰

风清扬

再配置:

再看分词:

  1. localhost:/_analyze
  2.  
  3. post
  4.  
  5. {"text":"陈秀峰",
  6. "analyzer":"ik_smart"
  7.  
  8. }
  9.  
  10. 结果:
  11. {
  12. "tokens": [
  13. {
  14. "token": "陈秀峰",
  15. "start_offset": ,
  16. "end_offset": ,
  17. "type": "CN_WORD",
  18. "position":
  19. }
  20. ]
  21. }

可以看出已经分词

再测试下:

  1. localhost:/_analyze
  2.  
  3. {"text":"中华人民共和国人民大会堂",
  4. "analyzer":"ik_smart"
  5.  
  6. }
  7.  
  8. {
  9. "tokens": [
  10. {
  11. "token": "中华人民共和国人民大会堂",
  12. "start_offset": ,
  13. "end_offset": ,
  14. "type": "CN_WORD",
  15. "position":
  16. }
  17. ]
  18. }

到此可以看出已经生效

 六  映射维护

  1  text    

    1)analyzer

    通过analyzer属性指定分词器。

    下边指定name的字段类型为text,使用ik分词器的ik_max_word分词模式。    

  1. "name": {
  2.                   "type": "text",
  3.                   "analyzer":"ik_max_word"
  4.    }

  上边指定了analyzer是指在索引和搜索都使用ik_max_word,如果单独想定义搜索时使用的分词器则可以通过search_analyzer属性。

对于ik分词器建议是索引时使用ik_max_word将搜索内容进行细粒度分词,搜索时使用ik_smart提高搜索精确性。

  索引的时候采用最细粒度的分词 ik_max_word,搜索的时候采用粗粒度的分词ik_smart,在搜索的时候采用粗粒度的分词就方便更精确的匹配

  例如:我搜索,陈秀峰  三个字,那么采用最粗粒度的分词,去搜索陈秀峰,那么可以精确匹配到这个,如果采用最细粒度的分词,那么就会搜索到,陈, 秀,峰这些,导致搜索的精确性

  1. "name": {
  2.                   "type": "text",
  3.                   "analyzer":"ik_max_word",
  4.                   "search_analyzer":"ik_smart"
  5.    }

   2)index

    通过index属性指定是否索引。

    默认为index=true,即要进行索引,只有进行索引才可以从索引库搜索到。

    但是也有一些内容不需要索引,比如:商品图片地址只被用来展示图片,不进行搜索图片,此时可以将index设为false。

    删除索引,重新创建映射,将pic的index设置为false,尝试根据pic去搜索,结果搜索不到数据

 

  1. "name": {
  2.   "type": "text",           
  3.               "index":false
  4.            }

看如下,如果将index设置为flase,将不会进行分词,那么这个字段查询只会根据原型来查询  

    3) store
    是否在source之外存储,每个文档索引后会在 ES中保存一份原始文档,存放在"_source"中,一般情况下不需要设置store为true,因为在_source中已经有一份原始文档了。
 
postman操作一下:
  1. http://localhost:9200/chenxuyou/doc/_mapping
  2.  
  3. post
  4.  
  5. 内容:
  6. {
  7. "properties": {
  8. "name": {
  9. "type": "text",
  10. "analyzer": "ik_max_word",
  11. "search_analyzer": "ik_smart"
  12. },
  13. "description": {
  14. "type": "text",
  15. "analyzer": "ik_max_word",
  16. "search_analyzer": "ik_smart"
  17. },
  18. "addr": {
  19. "type": "text",
  20. "index": false
  21. },
  22. "nickname": {
  23. "type": "text"
  24. }
  25. }
  26. }
  27.  
  28. 结果:
  29. {
  30. "acknowledged": true
  31. }

插入数据:

  1. http://localhost:9200/chenxuyou/doc/4028e58161bcf7f40161bcf8b77c0000
  2. post
  3.  
  4. {
  5. "name":"es学习",
  6. "description":"ES是一个基于RESTful web接口并且构建在Apache Lucene之上的开源分布式搜索引擎。",
  7. "addr":"ES还是一个分布式文档数据库",
  8. "nickname":"aaaaaaaaaaaaaaa"
  9.  
  10. }
  11.  
  12. {
  13. "_index": "chenxuyou",
  14. "_type": "doc",
  15. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  16. "_version": ,
  17. "result": "created",
  18. "_shards": {
  19. "total": ,
  20. "successful": ,
  21. "failed":
  22. },
  23. "_seq_no": ,
  24. "_primary_term":
  25. }

可以看到成功了

那么我们来进行搜索下,由于addr的index设置为false了,所以无法分词

  1. http://localhost:9200/chenxuyou/_search?q=name:学习
  2.  
  3. {
  4. "took": ,
  5. "timed_out": false,
  6. "_shards": {
  7. "total": ,
  8. "successful": ,
  9. "skipped": ,
  10. "failed":
  11. },
  12. "hits": {
  13. "total": ,
  14. "max_score": 0.2876821,
  15. "hits": [
  16. {
  17. "_index": "chenxuyou",
  18. "_type": "doc",
  19. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  20. "_score": 0.2876821,
  21. "_source": {
  22. "name": "es学习",
  23. "description": "ES是一个基于RESTful web接口并且构建在Apache Lucene之上的开源分布式搜索引擎。",
  24. "addr": "ES还是一个分布式文档数据库",
  25. "nickname": "aaaaaaaaaaaaaaa"
  26. }
  27. }
  28. ]
  29. }
  30. }
  1. http://localhost:9200/chenxuyou/_search?q=description:构建
  2.  
  3. {
  4. "took": ,
  5. "timed_out": false,
  6. "_shards": {
  7. "total": ,
  8. "successful": ,
  9. "skipped": ,
  10. "failed":
  11. },
  12. "hits": {
  13. "total": ,
  14. "max_score": 0.2876821,
  15. "hits": [
  16. {
  17. "_index": "chenxuyou",
  18. "_type": "doc",
  19. "_id": "4028e58161bcf7f40161bcf8b77c0000",
  20. "_score": 0.2876821,
  21. "_source": {
  22. "name": "es学习",
  23. "description": "ES是一个基于RESTful web接口并且构建在Apache Lucene之上的开源分布式搜索引擎。",
  24. "addr": "ES还是一个分布式文档数据库",
  25. "nickname": "aaaaaaaaaaaaaaa"
  26. }
  27. }
  28. ]
  29. }
  30. }
  1. http://localhost:9200/chenxuyou/_search?q=addr:ES
  2.  
  3. {
  4. "took": ,
  5. "timed_out": false,
  6. "_shards": {
  7. "total": ,
  8. "successful": ,
  9. "skipped": ,
  10. "failed":
  11. },
  12. "hits": {
  13. "total": ,
  14. "max_score": null,
  15. "hits": []
  16. }
  17. }

由此可知,所有的都支持分词,凡是index指定为falase的就不支持分词查询

keyword关键字字段 

  上边介绍的 text文本字段在映射时要设置分词器,keyword字段为关键字字段,通常搜索keyword是按照整体搜

索,所以创建keyword字段的索引时是不进行分词的,比如:邮政编码、手机号码、身份证等。keyword字段通常

用于过虑、排序、聚合等。

  1. http://localhost:9200/chenxuyou2/doc/_mapping
  2.  
  3. post
  4.  
  5. {
  6. "properties": {
  7. "name": {
  8. "type": "text",
  9. "analyzer": "ik_max_word",
  10. "search_analyzer": "ik_smart"
  11. },
  12. "description": {
  13. "type": "text",
  14. "analyzer": "ik_max_word",
  15. "search_analyzer": "ik_smart"
  16. },
  17. "addr": {
  18. "type": "text",
  19. "index": false
  20. },
  21. "nickname": {
  22. "type": "keyword"
  23. }
  24. }
  25. }
  26.  
  27. 结果:
  28. {
  29. "acknowledged": true
  30. }

插入数据:

  1. http://localhost:9200/chenxuyou2/doc/4028e58161bcf7f40161bcf8b77c000
  2.  
  3. post
  4.  
  5. {
  6. "name":"es学习",
  7. "description":"ES是一个基于RESTful web接口并且构建在Apache Lucene之上的开源分布式搜索引擎。",
  8. "addr":"ES还是一个分布式文档数据库",
  9. "nickname":""
  10.  
  11. }
  12. 结果:
  13. {
  14. "_index": "chenxuyou2",
  15. "_type": "doc",
  16. "_id": "4028e58161bcf7f40161bcf8b77c000",
  17. "_version": ,
  18. "result": "created",
  19. "_shards": {
  20. "total": ,
  21. "successful": ,
  22. "failed":
  23. },
  24. "_seq_no": ,
  25. "_primary_term":
  26. }

操作:

  1. http://localhost:9200/chenxuyou2/_search?q=nickname:12345
  2.  
  3. {
  4. "took": ,
  5. "timed_out": false,
  6. "_shards": {
  7. "total": ,
  8. "successful": ,
  9. "skipped": ,
  10. "failed":
  11. },
  12. "hits": {
  13. "total": ,
  14. "max_score": null,
  15. "hits": []
  16. }
  17. }
  18.  
  19. http://localhost:9200/chenx2/_search?q=nickname:123456
  20.  
  21. {
  22. "took": ,
  23. "timed_out": false,
  24. "_shards": {
  25. "total": ,
  26. "successful": ,
  27. "skipped": ,
  28. "failed":
  29. },
  30. "hits": {
  31. "total": ,
  32. "max_score": 0.2876821,
  33. "hits": [
  34. {
  35. "_index": "chenxuyou2",
  36. "_type": "doc",
  37. "_id": "4028e58161bcf7f40161bcf8b77c000",
  38. "_score": 0.2876821,
  39. "_source": {
  40. "name": "es学习",
  41. "description": "ES是一个基于RESTful web接口并且构建在Apache Lucene之上的开源分布式搜索引擎。",
  42. "addr": "ES还是一个分布式文档数据库",
  43. "nickname": ""
  44. }
  45. }
  46. ]
  47. }
  48. }

date日期类型

日期类型不用设置分词器。

通常日期类型的字段用于排序。

1)format

通过format设置日期格式

例子:

下边的设置允许date字段存储年月日时分秒、年月日及毫秒三种格式。

  1. {
  2. "properties": {    
  3.         "timestamp": {
  4.           "type":   "date",
  5.           "format": "yyyy‐MM‐dd HH:mm:ss||yyyy‐MM‐dd"
  6.         }
  7.       }
  8. }

数字类型:

1、尽量选择范围小的类型,提高搜索效率

2、对于浮点数尽量用比例因子,比如一个价格字段,单位为元,我们将比例因子设置为100这在ES中会按 分 存

储,映射如下:

  1. "price": {
  2. "type": "scaled_float",
  3. "scaling_factor":
  4. },

由于比例因子为100,如果我们输入的价格是23.45则ES中会将23.45乘以100存储在ES中。
如果输入的价格是23.456,ES会将23.456乘以100再取一个接近原始值的数,得出2346。
使用比例因子的好处是整型比浮点型更易压缩,节省磁盘空间。

   

elasticSerach 知识学习的更多相关文章

  1. 网络知识学习2---(IP地址、子网掩码)(学习还不深入,待完善)

    紧接着:网络知识学习1 1.IP地址    IP包头的结构如图 A.B.C网络类别的IP地址范围(图表) A.B.C不同的分配网络数和主机的方式(A是前8个IP地址代表网络,后24个代表主机:B是16 ...

  2. HTML5标签汇总及知识学习线路总结

    HTML5标签汇总,以及知识学习线路总结.

  3. 安全测试3_Web后端知识学习

    其实中间还应该学习下web服务和数据库的基础,对于web服务大家可以回家玩下tomcat或者wamp等东西,数据库的话大家掌握基本的增删该查就好了,另外最好掌握下数据库的内置函数,如:concat() ...

  4. GCC基础知识学习

    GCC基础知识学习 一.GCC编译选项解析 常用编译选项 命令格式:gcc [选项] [文件名] -E:仅执行编译预处理: -S:将C代码转换为汇编代码: -c:仅执行编译操作,不进行连接操作: -o ...

  5. 毕业设计预习:VHDL入门知识学习(一) VHDL程序基本结构

    VHDL入门知识学习(一) VHDL程序基本结构 简介 VHDL程序基本结构 简介 概念: HDL-Hardware Description Language-硬件描述语言-描述硬件电路的功能.信号连 ...

  6. 「日常训练&知识学习」单调栈

    这几天的知识学习比较多,因为时间不够了.加油吧,为了梦想. 这里写几条简单的单调栈作为题解记录,因为单调栈的用法很简单,可是想到并转化成用这个需要一些题目的积淀. 相关博客参见:https://blo ...

  7. (转)Linux基础知识学习

    Linux基础知识学习 原文:http://blog.csdn.net/ye_wei_yang/article/details/52777499 一.Linux的磁盘分区及目录 Linux的配置是通过 ...

  8. Objective-c基础知识学习笔记

    Objective-c基础知识学习笔记(一) 一直有记录笔记的习惯.但非常久没分享一些东西了,正好上半年開始学习IOS了,如今有空写点.因开发须要,公司特意为我们配置了几台新MAC.还让我们自学了2周 ...

  9. MySQL索引知识学习笔记

    目录 一.索引的概念 二.索引分类 三.索引用法 四 .索引架构简介 五.索引适用的情况 六.索引不适用的情况 继我的上篇博客:Oracle索引知识学习笔记,再记录一篇MySQL的索引知识学习笔记,本 ...

随机推荐

  1. 「NOIP模拟赛」数位和乘积(dp,高精)

    统计方案数,要么组合数,要么递推(dp)了. 这是有模拟赛历史以来爆炸最狠的一次 T1写了正解,也想到开long long,但是开错了地方然后数组开大了结果100->0 T3看错题本来简单模拟又 ...

  2. python入门之五种字典创建方法

    a = dict(one = 1, tow = 2, three = 3)b = {'one' :1,'tow' :2 , 'three' :3}c = dict (zip(['one', 'tow' ...

  3. css3 svg路径蒙版动画

    css3 svg路径蒙版动画 具体看https://www.cnblogs.com/oubenruing/p/9568954.html 还有个更好控制的写法<pre><!DOCTYP ...

  4. ValueError: zero-size array to reduction operation maximum which has no identity

    数据打印到第530行之后出现以下异常,求解!

  5. Windows对python文件加密

    最近项目需要对部分python文件加密,调研了部分方法都觉得不可行,最后采用了将python转换成so文件.pyd文件的方法.so文件,为liunx下的动态链接库文件,在windows下为dll文件, ...

  6. Eclipse下载安装并运行第一个Hello world(详细)

    Eclipse下载安装并运行第一个Hello world(详细) 1.下载安装和配置JDK JDK详细的安装教程参考:https://www.cnblogs.com/mxxbc/p/11845150. ...

  7. 《计算机网络 自顶向下方法》 第3章 运输层 Part1

    由于个人精力和智商有限,又喜欢想太多.钻牛角尖,导致学习系统性知识很痛苦,尝试改变学习方式,慢慢摸索 现在看到 rdt2.0,又有点看不下去 现在的想法: 要有个目标,且有截止时间(作业模式.考试模式 ...

  8. 启动Spring Tool Suite 4时出现 could not find tools.jar spring boot live hovers....弹窗

    第一步:检查一下STS启动时的加载环境 Help  —› About Spring Tool Suite 4 —› Installation Details —› Configuration 本人已经 ...

  9. PHP Laravel 中使用简单的方法跟踪用户是否在线

    今天,我的任务是,在 Laravel 应用程序用户个人资料页面上,用户名旁边添加一个绿点,表示他们是否在线.我首先想到的是,我们将需要启动一个 node.js 服务器并跟踪每个用户的活动套接字连接.然 ...

  10. 领扣(LeetCode)字母大小写全排列 个人题解

    给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串.返回所有可能得到的字符串集合. 示例: 输入: S = "a1b2" 输出: ["a1 ...