elasticsearchElasticsearch分布式搜索引擎说说Elasticsearch那点事

Elasticsearch5.6搭建及拼音中文混合搜索实现

2017-10-01  本文已影响164人  BIGUFO

功能

环境搭建

  1. 从官网下载压缩包 elasticsearch-5.6.1.tar.gz;
  2. 解压 tar -zxvf elasticsearch-5.6.1.tar.gz $ES_HOME
  3. 因es只能由除root以外的用户启动,则给予相应的权限,如给common用户,chown -R common:root elasticsearch-5.6.1
  4. 配置,vi $ES_HOME/config/elasticsearch.yml
    主要修改以下配置
    cluster.name: **
    node.name: node-1
    network.host: 192.168.0.250
    http.port: 9200
  5. 添加ik、pinyin插件,将对应版本的插件下载放到$ES_HOME/plugins下即可
    https://github.com/medcl/elasticsearch-analysis-ik
    https://github.com/medcl/elasticsearch-analysis-pinyin
  6. 用户common启动es

bin/elasticsearch -d 后台启动

  1. 可通过chrome插件 elasticsearch-head 连接es

应用

curl -XPUT "http://localhost:9200/index_name/" -d'
{
    "index": {
        "analysis": {
            "analyzer": {
                "ik_pinyin_analyzer": {
                    "type": "custom",
                    "tokenizer": "ik_smart",
                    "filter": ["my_pinyin", "word_delimiter"]
                }
            },
            "filter": {
                "my_pinyin": {
                    "type": "pinyin",
                    "first_letter": "prefix",
                    "padding_char": " "
                }
            }
        }
    }
}
curl -XPOST http://localhost:9200/index_name/app/_mapping -d'
{
    "app": {
        "properties": {
            "appname": {
                "type": "keyword",
                "fields": {
                    "pinyin": {
                        "type": "text",
                        "store": "no",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "ik_pinyin_analyzer",
                        "boost": 10
                    }
                }
            }
        }
    }
}
curl -XGET http://localhost:9200/index_name/app/_search?q=appname.pinyin:wangzhe荣耀
上一篇 下一篇

猜你喜欢

热点阅读