elasticsearch简单使用

elasticsearch 部署:
由于本人的硬件设备有限,所以需要在一台服务器上布置三个elasticsearch实例,所以需要修改如下配置:
cluster.name: cluster1
node.name: node1
node.data: true
node.master: true
path.data: d:\\esdata\data\data1
path.logs: d:\\esdata\logs\log1
需要注意的是 不要指定http.port: 9200这个选项,应为单机部署三个实例会导致端口冲突
其他类似修改

elasticsearch 添加ik分词器:
1.首先在https://github.com/medcl/elasticsearch-analysis-ik/releases下载于elasticsearch对应的ik编译好的包
也可以自己重新编译,下载地址https://github.com/medcl/elasticsearch-analysis-ik.git)
2.把压缩包解压在elasticsearch安装目录下的plugin目下的ik文件夹下(如果没有可以手动建)
3.在elasticsearch.yml配置文件中加入一句:index.analysis.analyzer.ik.type: "ik"


elasticsearch支持数据更新:
全部更新:
curl  -XPOST  "http://127.0.0.1:9200/index/type/id" -d '{}'
局部更新:
如果通过脚本更新需要在elasticsearch.yml中加入一条
script.inline: on
curl  -XPOST  "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"script":"ctx._source.totalnum+=1","upsert":{"totalnum":0}}'
上面的命令会对id对应的文档中的totalnum列加一操作
也可通过doc进行对文档的某一列和几列重新写入
curl  -XPOST  "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"doc":{"totalnum":20}}'


elasticsearch支持数据聚合:
因为我用的是根据关键字词去聚合,但是每一条新闻内容可能包含多个关键字词(用空格分割)
随意在索引模版创建时指定:
    "keywords": {
        "analyzer": "whitespace",
        "type": "string"
    }
注意:如果你对进行分词过的列聚合,那么elasticsearch会根据按照分词后的结果聚合,
curl -XPOST "http://127.0.0.1:9200/news/dynamic/_search?pretty" -d '{"aggs":{"group_by_classification":{"terms":{"field":"%s"}}}}'


也可以实现:select field1,sum(field2) from table1 group by field1;
{"aggs":{"group_by_classification":{"terms":{"field":"field1"},"aggs":{"sum":{"field":"field2"}}}}}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值