elasticsearch-5.1.2安装pinyin分词器并测试

下载插件包

[listen@localhost elasticsearch-cluster]$ pwd
/home/listen/elasticsearch-cluster
[listen@localhost elasticsearch-cluster]$ git clone https://github.com/medcl/elasticsearch-analysis-pinyin.git
Cloning into 'elasticsearch-analysis-pinyin'...
remote: Counting objects: 851, done.
remote: Total 851 (delta 0), reused 0 (delta 0), pack-reused 851
Receiving objects: 100% (851/851), 2.53 MiB | 190.00 KiB/s, done.
Resolving deltas: 100% (305/305), done.
[listen@localhost elasticsearch-cluster]$ ll
total 33732
-rw-rw-r--. 1 listen listen   244848 Jan 19 00:31 accounts.json
-rwxr-xr-x. 1 listen listen 33299777 Jan 18 18:31 elasticsearch-5.1.2.tar.gz
drwxrwxr-x. 7 listen listen     4096 Jan 19 19:20 elasticsearch-analysis-ik
drwxrwxr-x. 5 listen listen     4096 Jan 19 23:02 elasticsearch-analysis-pinyin
drwxrwxr-x. 5 listen listen     4096 Jan 18 23:27 elasticsearch-head-master
-rw-rw-r--. 1 listen listen   908930 Jan 18 22:41 elasticsearch-head-master.zip
drwxr-xr-x. 9 listen listen     4096 Jan 18 18:43 elasticsearch-node1
drwxr-xr-x. 9 listen listen     4096 Jan 18 18:50 elasticsearch-node2
-rw-------. 1 listen listen    59366 Jan 19 02:16 nohup.out
-rw-r--r--. 1 root   root       2544 Jan 18 23:28 npm-debug.log
[listen@localhost elasticsearch-cluster]$ cd elasticsearch-analysis-pinyin/
[listen@localhost elasticsearch-analysis-pinyin]$ ll
total 32
drwxrwxr-x. 2 listen listen    29 Jan 19 23:02 lib
-rw-rw-r--. 1 listen listen 11357 Jan 19 23:02 LICENSE.txt
-rw-rw-r--. 1 listen listen 11224 Jan 19 23:02 pom.xml
-rw-rw-r--. 1 listen listen  7662 Jan 19 23:02 README.md
drwxrwxr-x. 4 listen listen    28 Jan 19 23:02 src

编译

[listen@localhost elasticsearch-analysis-pinyin]$ mvn package
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.elasticsearch:elasticsearch-analysis-pinyin:jar:5.1.2
[WARNING] 'version' contains an expression but should be a constant. @ org.elasticsearch:elasticsearch-analysis-pinyin:${elasticsearch.version}, /home/listen/elasticsearch-cluster/elasticsearch-analysis-pinyin/pom.xml, line 9, column 14
[WARNING] 'dependencies.dependency.systemPath' for org.nlpcn:nlp-lang:jar should not point at files within the project directory, ${basedir}/lib/nlp-lang-1.7.jar will be unresolvable by dependent projects @ org.elasticsearch:elasticsearch-analysis-pinyin:${elasticsearch.version}, /home/listen/elasticsearch-cluster/elasticsearch-analysis-pinyin/pom.xml, line 76, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building elasticsearch-analysis-pinyin 5.1.2
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/1.2/maven-enforcer-plugin-1.2.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/1.2/maven-enforcer-plugin-1.2.pom (6 KB at 2.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer/1.2/enforcer-1.2.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/enforcer/enforcer/1.2/enforcer-1.2.pom (11 KB at 25.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/1.2/maven-enforcer-plugin-1.2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-enforcer-plugin/1.2/maven-enforcer-plugin-1.2.jar (25 KB at 46.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.19.1/maven-surefire-plugin-2.19.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.19.1/maven-surefire-plugin-2.19.1.pom (6 KB at 14.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.19.1/surefire-2.19.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/sure
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar (22 KB at 23.3 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.0.2/plexus-io-2.0.2.jar (57 KB at 31.7 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar (10 KB at 0.7 KB/sec)
[INFO] Reading assembly descriptor: /home/listen/elasticsearch-cluster/elasticsearch-analysis-pinyin/src/main/assemblies/plugin.xml
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'org.apache.lucene:lucene-pinyin'

[INFO] Building zip: /home/listen/elasticsearch-cluster/elasticsearch-analysis-pinyin/target/releases/elasticsearch-analysis-pinyin-5.1.2.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:56.647s
[INFO] Finished at: Thu Jan 19 23:49:14 PST 2017
[INFO] Final Memory: 20M/57M
[INFO] ------------------------------------------------------------------------

安装pinyin分词器

[listen@localhost elasticsearch-analysis-pinyin]$ cd target/
[listen@localhost target]$ ll
total 40
drwxrwxr-x. 2 listen listen    60 Jan 19 23:49 archive-tmp
drwxrwxr-x. 3 listen listen    78 Jan 19 23:47 classes
-rw-rw-r--. 1 listen listen 23480 Jan 19 23:47 elasticsearch-analysis-pinyin-5.1.2.jar
-rw-rw-r--. 1 listen listen 13779 Jan 19 23:47 elasticsearch-analysis-pinyin-5.1.2-sources.jar
drwxrwxr-x. 3 listen listen    24 Jan 19 23:47 generated-sources
drwxrwxr-x. 3 listen listen    29 Jan 19 23:47 generated-test-sources
drwxrwxr-x. 2 listen listen    27 Jan 19 23:47 maven-archiver
drwxrwxr-x. 3 listen listen    34 Jan 19 23:47 maven-status
drwxrwxr-x. 2 listen listen    52 Jan 19 23:49 releases
drwxrwxr-x. 3 listen listen    39 Jan 19 23:47 test-classes
[listen@localhost target]$ cd releases/
[listen@localhost releases]$ ll
total 2260
-rw-rw-r--. 1 listen listen 2312530 Jan 19 23:49 elasticsearch-analysis-pinyin-5.1.2.zip
[listen@localhost releases]$ mkdir /home/listen/elasticsearch-cluster/elasticsearch-node1/plugins/pinyin
[listen@localhost releases]$ mkdir /home/listen/elasticsearch-cluster/elasticsearch-node2/plugins/pinyin
[listen@localhost releases]$ cp elasticsearch-analysis-pinyin-5.1.2.zip /home/listen/elasticsearch-cluster/elasticsearch-node1/plugins/pinyin
[listen@localhost releases]$ cp elasticsearch-analysis-pinyin-5.1.2.zip /home/listen/elasticsearch-cluster/elasticsearch-node2/plugins/pinyin
[listen@localhost releases]$ cd /home/listen/elasticsearch-cluster/elasticsearch-node1/plugins/pinyin
[listen@localhost pinyin]$ unzip elasticsearch-analysis-pinyin-5.1.2.zip 
Archive:  elasticsearch-analysis-pinyin-5.1.2.zip
  inflating: nlp-lang-1.7.jar        
  inflating: plugin-descriptor.properties  
  inflating: elasticsearch-analysis-pinyin-5.1.2.jar  
[listen@localhost pinyin]$ cd /home/listen/elasticsearch-cluster/elasticsearch-node2/plugins/pinyin
[listen@localhost pinyin]$ unzip elasticsearch-analysis-pinyin-5.1.2.zip 
Archive:  elasticsearch-analysis-pinyin-5.1.2.zip
  inflating: nlp-lang-1.7.jar        
  inflating: plugin-descriptor.properties  
  inflating: elasticsearch-analysis-pinyin-5.1.2.jar  
[listen@localhost pinyin]$ 

重启服务,测试

[listen@localhost elasticsearch-cluster]$ ./elasticsearch-node2/bin/elasticsearch
[2017-01-19T23:53:34,879][INFO ][o.e.n.Node               ] [listen-node2] initializing ...
[2017-01-19T23:53:35,208][INFO ][o.e.e.NodeEnvironment    ] [listen-node2] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.1gb], net total_space [17.6gb], spins? [unknown], types [rootfs]
[2017-01-19T23:53:35,208][INFO ][o.e.e.NodeEnvironment    ] [listen-node2] heap size [505.6mb], compressed ordinary object pointers [unknown]
[2017-01-19T23:53:35,323][INFO ][o.e.n.Node               ] [listen-node2] node name [listen-node2], node ID [WC-gRq-HQTGwlaJfERsm9A]
[2017-01-19T23:53:35,333][INFO ][o.e.n.Node               ] [listen-node2] version[5.1.2], pid[11376], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-514.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [aggs-matrix-stats]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [ingest-common]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-expression]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-groovy]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-mustache]
[2017-01-19T23:53:39,087][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [lang-painless]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [percolator]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [reindex]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [transport-netty3]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded module [transport-netty4]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded plugin [analysis-ik]
[2017-01-19T23:53:39,088][INFO ][o.e.p.PluginsService     ] [listen-node2] loaded plugin [analysis-pinyin]
[2017-01-19T23:53:55,668][INFO ][o.e.n.Node               ] [listen-node2] initialized
[2017-01-19T23:53:55,675][INFO ][o.e.n.Node               ] [listen-node2] starting ...
[2017-01-19T23:53:57,452][INFO ][o.e.t.TransportService   ] [listen-node2] publish_address {192.168.159.129:9300}, bound_addresses {192.168.159.129:9300}
[2017-01-19T23:53:57,509][INFO ][o.e.b.BootstrapCheck     ] [listen-node2] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-01-19T23:54:01,903][INFO ][o.e.c.s.ClusterService   ] [listen-node2] new_master {listen-node2}{WC-gRq-HQTGwlaJfERsm9A}{pC-VuYioSVueiJmh2aVPxw}{192.168.159.129}{192.168.159.129:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-01-19T23:54:03,947][INFO ][o.e.h.HttpServer         ] [listen-node2] publish_address {192.168.159.129:9202}, bound_addresses {192.168.159.129:9202}
[2017-01-19T23:54:03,967][INFO ][o.e.n.Node               ] [listen-node2] started
[2017-01-19T23:54:04,686][INFO ][o.w.a.d.Monitor          ] try load config from /home/listen/elasticsearch-cluster/elasticsearch-node2/config/analysis-ik/IKAnalyzer.cfg.xml
[2017-01-19T23:54:04,691][INFO ][o.w.a.d.Monitor          ] try load config from /home/listen/elasticsearch-cluster/elasticsearch-node2/plugins/ik/config/IKAnalyzer.cfg.xml
[2017-01-19T23:54:10,756][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/mydict.dic
[2017-01-19T23:54:10,940][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/single_word_low_freq.dic
[2017-01-19T23:54:11,111][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/ext_stopword.dic
[2017-01-19T23:54:19,123][INFO ][o.e.g.GatewayService     ] [listen-node2] recovered [1] indices into cluster_state
[2017-01-19T23:54:37,459][WARN ][o.e.m.j.JvmGcMonitorService] [listen-node2] [gc][young][32][11] duration [10s], collections [1]/[10.5s], total [10s]/[10.2s], memory [87.3mb]->[53.9mb]/[505.6mb], all_pools {[young] [51.1mb]->[183.1kb]/[51.2mb]}{[survivor] [6.3mb]->[6.3mb]/[6.3mb]}{[old] [29.8mb]->[47.4mb]/[448mb]}
[2017-01-19T23:54:37,483][WARN ][o.e.m.j.JvmGcMonitorService] [listen-node2] [gc][32] overhead, spent [10s] collecting in the last [10.5s]
[2017-01-19T23:54:37,763][INFO ][o.e.c.r.a.AllocationService] [listen-node2] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[bank][4]] ...]).
[listen@localhost elasticsearch-cluster]$ ./elasticsearch-node1/bin/elasticsearch
[2017-01-19T23:53:26,822][INFO ][o.e.n.Node               ] [listen-node1] initializing ...
[2017-01-19T23:53:29,733][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.1gb], net total_space [17.6gb], spins? [unknown], types [rootfs]
[2017-01-19T23:53:29,733][INFO ][o.e.e.NodeEnvironment    ] [listen-node1] heap size [505.6mb], compressed ordinary object pointers [unknown]
[2017-01-19T23:53:30,863][INFO ][o.e.n.Node               ] [listen-node1] node name [listen-node1], node ID [HkkRtyJSTlC15ysyrsJeJg]
[2017-01-19T23:53:30,991][INFO ][o.e.n.Node               ] [listen-node1] version[5.1.2], pid[11348], build[c8c4c16/2017-01-11T20:18:39.146Z], OS[Linux/3.10.0-514.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_111/25.111-b14]
[2017-01-19T23:53:54,887][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [aggs-matrix-stats]
[2017-01-19T23:53:54,893][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [ingest-common]
[2017-01-19T23:53:54,893][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-expression]
[2017-01-19T23:53:54,894][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-groovy]
[2017-01-19T23:53:54,894][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-mustache]
[2017-01-19T23:53:54,894][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [lang-painless]
[2017-01-19T23:53:54,895][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [percolator]
[2017-01-19T23:53:54,895][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [reindex]
[2017-01-19T23:53:54,895][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty3]
[2017-01-19T23:53:54,896][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded module [transport-netty4]
[2017-01-19T23:53:54,898][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded plugin [analysis-ik]
[2017-01-19T23:53:54,898][INFO ][o.e.p.PluginsService     ] [listen-node1] loaded plugin [analysis-pinyin]
[2017-01-19T23:54:50,754][INFO ][o.e.n.Node               ] [listen-node1] initialized
[2017-01-19T23:54:51,009][INFO ][o.e.n.Node               ] [listen-node1] starting ...
[2017-01-19T23:54:52,365][INFO ][o.e.t.TransportService   ] [listen-node1] publish_address {192.168.159.129:9301}, bound_addresses {192.168.159.129:9301}
[2017-01-19T23:54:52,376][INFO ][o.e.b.BootstrapCheck     ] [listen-node1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-01-19T23:54:56,075][INFO ][o.e.c.s.ClusterService   ] [listen-node1] new_master {listen-node1}{HkkRtyJSTlC15ysyrsJeJg}{rmNi2-FVTUCcohm_PeTRbQ}{192.168.159.129}{192.168.159.129:9301}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2017-01-19T23:54:56,668][INFO ][o.e.h.HttpServer         ] [listen-node1] publish_address {192.168.159.129:9201}, bound_addresses {192.168.159.129:9201}
[2017-01-19T23:54:56,668][INFO ][o.e.n.Node               ] [listen-node1] started
[2017-01-19T23:54:57,677][INFO ][o.w.a.d.Monitor          ] try load config from /home/listen/elasticsearch-cluster/elasticsearch-node1/config/analysis-ik/IKAnalyzer.cfg.xml
[2017-01-19T23:54:57,701][INFO ][o.w.a.d.Monitor          ] try load config from /home/listen/elasticsearch-cluster/elasticsearch-node1/plugins/ik/config/IKAnalyzer.cfg.xml
[2017-01-19T23:55:02,996][WARN ][o.e.m.j.JvmGcMonitorService] [listen-node1] [gc][young][8][10] duration [3.4s], collections [1]/[4.2s], total [3.4s]/[14s], memory [50.4mb]->[37.5mb]/[505.6mb], all_pools {[young] [24mb]->[170.6kb]/[51.2mb]}{[survivor] [6.3mb]->[6.3mb]/[6.3mb]}{[old] [20mb]->[31.1mb]/[448mb]}
[2017-01-19T23:55:03,079][WARN ][o.e.m.j.JvmGcMonitorService] [listen-node1] [gc][8] overhead, spent [3.4s] collecting in the last [4.2s]
[2017-01-19T23:55:03,205][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/mydict.dic
[2017-01-19T23:55:03,361][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/single_word_low_freq.dic
[2017-01-19T23:55:03,530][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/ext_stopword.dic
[2017-01-19T23:55:09,354][INFO ][o.e.g.GatewayService     ] [listen-node1] recovered [2] indices into cluster_state
[2017-01-19T23:55:12,104][WARN ][o.e.m.j.JvmGcMonitorService] [listen-node1] [gc][17] overhead, spent [598ms] collecting in the last [1s]
[2017-01-19T23:55:12,632][INFO ][o.e.c.r.a.AllocationService] [listen-node1] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[bank][0]] ...]).
[listen@localhost elasticsearch-cluster]$ curl -XPUT http://192.168.159.129:9201/pinyinindex/?pretty -d'
> {
>     "index" : {
>         "analysis" : {
>             "analyzer" : {
>                 "pinyin_analyzer" : {
>                     "tokenizer" : "my_pinyin"
>                     }
>             },
>             "tokenizer" : {
>                 "my_pinyin" : {
>                     "type" : "pinyin",
>                     "keep_separate_first_letter" : false,
>                     "keep_full_pinyin" : true,
>                     "keep_original" : true,
>                     "limit_first_letter_length" : 16,
>                     "lowercase" : true
>                 }
>             }
>         }
>     }
> }'
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}
[listen@localhost elasticsearch-cluster]$ 
[listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/pinyinindex/_analyze?text=%e5%88%98%e5%be%b7%e5%8d%8e&analyzer=pinyin_analyzer&pretty'
{
  "tokens" : [
    {
      "token" : "liu",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "word",
      "position" : 0
    },
    {
      "token" : "de",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "word",
      "position" : 1
    },
    {
      "token" : "hua",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "word",
      "position" : 2
    },
    {
      "token" : "刘德华",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 3
    },
    {
      "token" : "ldh",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "word",
      "position" : 4
    }
  ]
}
[listen@localhost elasticsearch-cluster]$ 
#下面这种是错误的用法,不支持在客户端工具中写入中文
[listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/pinyinindex/_analyze?text=刘德华&analyzer=pinyin_analyzer&pretty'
{
  "tokens" : [
    {
      "token" : "¥ネリ¥ᄒᄋ¥ヘホ",
      "start_offset" : 0,
      "end_offset" : 9,
      "type" : "word",
      "position" : 0
    }
  ]
}
[listen@localhost elasticsearch-cluster]$ 

创建一个拼音类型的索引结构 

[listen@localhost elasticsearch-cluster]$ curl -XPOST http://192.168.159.129:9201/pinyinindex/folks/_mapping -d'
> {
>     "folks": {
>         "properties": {
>             "name": {
>                 "type": "keyword",
>                 "fields": {
>                     "pinyin": {
>                         "type": "text",
>                         "store": "no",
>                         "term_vector": "with_positions_offsets",
>                         "analyzer": "pinyin_analyzer",
>                         "boost": 10
>                     }
>                 }
>             }
>         }
>     }
> }'
{"acknowledged":true}[listen@localhost elasticsearch-cluster]$ 
[listen@localhost elasticsearch-cluster]$ 

插入一条数据:刘德华

[listen@localhost elasticsearch-cluster]$ curl -XPOST http://192.168.159.129:9201/pinyinindex/folks/andy?pretty -d'{"name":"刘德华"}'
{
  "_index" : "pinyinindex",
  "_type" : "folks",
  "_id" : "andy",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}
[listen@localhost elasticsearch-cluster]$ 

查询条件:de+hua

[listen@localhost elasticsearch-cluster]$ curl -XGET 'http://192.168.159.129:9201/pinyinindex/folks/_search?pretty&q=name.pinyin:de+hua'
{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.84748024,
    "hits" : [
      {
        "_index" : "pinyinindex",
        "_type" : "folks",
        "_id" : "andy",
        "_score" : 0.84748024,
        "_source" : {
          "name" : "刘德华"
        }
      }
    ]
  }
}
[listen@localhost elasticsearch-cluster]$ 

查询条件:ldh

[listen@localhost elasticsearch-cluster]$ curl -XGET 'http://192.168.159.129:9201/pinyinindex/folks/_search?q=name.pinyin:ldh&pretty'
{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.5649868,
    "hits" : [
      {
        "_index" : "pinyinindex",
        "_type" : "folks",
        "_id" : "andy",
        "_score" : 0.5649868,
        "_source" : {
          "name" : "刘德华"
        }
      }
    ]
  }
}
[listen@localhost elasticsearch-cluster]$ 

查询条件:liu

[listen@localhost elasticsearch-cluster]$ curl -XGET 'http://192.168.159.129:9201/pinyinindex/folks/_search?q=name.pinyin:liu&pretty'
{
  "took" : 22,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.84748024,
    "hits" : [
      {
        "_index" : "pinyinindex",
        "_type" : "folks",
        "_id" : "andy",
        "_score" : 0.84748024,
        "_source" : {
          "name" : "刘德华"
        }
      }
    ]
  }
}
[listen@localhost elasticsearch-cluster]$ 

查询条件:刘德华中文的转义码

[listen@localhost elasticsearch-cluster]$ curl -XGET 'http://192.168.159.129:9201/pinyinindex/folks/_search?q=name.pinyin:%e5%88%98%e5%be%b7&pretty'
{
  "took" : 22,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.5649868,
    "hits" : [
      {
        "_index" : "pinyinindex",
        "_type" : "folks",
        "_id" : "andy",
        "_score" : 0.5649868,
        "_source" : {
          "name" : "刘德华"
        }
      }
    ]
  }
}
[listen@localhost elasticsearch-cluster]$ 

 

转载于:https://my.oschina.net/Listening/blog/828427

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值