目前在使用es的大公司: https://www.elastic.co/use-caseshtml
Mongodb redis 在 elasticsearch面前就是一个玩笑 哈哈!java
要先下载java安装node
Java -version 查看是否安装python
能够用国内大神二次开发的版本 https://github.com/medcl/elasticsearch-rtflinux
碰见的错误git
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOMEgithub
解决方式:redis
要添加jdk配置到windows的环境中npm
JAVA_HOME django
C:\Program Files\Java\jdk1.8.0_131
此时不该有 \elasticsearch-rtf-master\bin\\..\config\jvm.options。
解决方式:
由于的你的路径中有括号,只要去掉括号就能够了
安装head插件:
下载 https://github.com/mobz/elasticsearch-head
下载 https://nodejs.org/en/ 安装nodejs
安装好nodejs就安装好了npm 能够用npm -v 测试下
网上安装教程不少,就能够安装。
推荐使用cnpm 利用的是淘宝的镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
百度下就能够看到不少资料,这里很少写了
整个安装elasticsearch的教程,能够百度均可用
启动 命令
启动elasticsearch 直接 elasticsearch.bat
启动 head 直接 cnpm run start
启动kibana 直接kibana.bat
若是是同一个索引的,要求是字段名称要相同
<>中是出现的位置,最后一个是出现的次数
以上的问题其实elasticsearch都已经帮咱们作好了
GET _search
{
"query": {
"match_all": {}
}
}
# es的文档、索引的CRUD操做
# 索引初始化操做
# 指定分片和副本的数量
# shards 一旦设置就不能修改了(注意)
# 创建5个分片,1个副本
PUT lagou
{
"settings": {
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
GET lagou/_settings
# 得到全部索引的setting
GET _all/_settings
GET _settings
# 得到指定索引的setting
GET .kibana,lagou/_settings
# 修改settings
PUT lagou/_settings
{
"number_of_replicas": 2
}
# 获取索引信息
GET _all
GET lagou
#put插入数据必定要有_id,能够本身指定
PUT lagou/job/1
{
"name":"ppp",
"age":12
}
#post插入数据,能够没有_id,他会本身随机生成一个_id
POST lagou/job/
{
"name":"ppp",
"age":13
}
# 只查看某条记录
GET lagou/job/1
# 只查看某条记录的某个字段
GET lagou/job/1?_source=name,age
# put修改文章 只要是_id是同样的,那就会直接覆盖
PUT lagou/job/1
{
"name":"ppp",
"age":12,
"gender":"male"
}
# post 能够指定某个字段作修改,不用用到所有的字段
# 通常都是用post
POST lagou/job/1/_update
{
"doc": {
"name2": "hello"
}
}
# 删除
# 删除某条记录
DELETE lagou/job/1
# 删除索引
DELETE lagou
# _mget多条查询
GET lagou/job/_mget
{
"ids":[1,"AWOcnK0u_fyJAeHWwkP7",12]
}
# _bulk用的很少
# 建立索引
PUT lagou22
{
"mappings": {
"job":{
"properties": {
"name":{
"type": "keyword"
},
"age":{
"type": "integer"
},
"gender":{
"type": "text"
}
}
}
}
}
PUT lagou22/job/1
{
"name":"pujinxiao",
"age":34,
"gender":"male"
}
# 查询 query
term 和 match 区别
term 不会给查询条件作分词,可是match会的
{
"query": {
"term": {
"title": "火石"
}
}
}
{
"query": {
"match": {
"title": "火石"
}
}
}
# 只要知足列表中的一个就能被查询出来
get map_news/index/_search
{
"query": {
"terms": {
"title": ["火石","python"]
}
}
}
# 控制查询返回的数量
get map_news/index/_search
{
"query": {
"term": {
"title": ["火石","python"]
}
},
"from":0,
"size":2
}
# match_phrase查询
# 短语查询
#他会把查询的内容分词,slop就是分词后的中间的长度,你能够本身控制
GET map_news/index/_search
{
"query": {
"match_phrase": {
"title": {
"query": "火石创造",
"slop":6
}
}
}
}
# multi_match
# 指定多个字段查询,
GET map_news/index/_search
{
"query": {
"multi_match": {
"query": "火石",
"fields": ["title","summary"]
}
}
}
# 搜索的权重是title是summary的三倍
"fields": ["title^3","summary"]
# 指定返回的字段
# _source 指定返回的字段,用excludes 是排除该字段
GET map_news/index/_search
{
"_source": {
"includes": ["title"]
},
"query": {
"match": {
"title": "火石"
}
}
}
# 经过sort把结果排序
GET map_news/index/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"update_time": {
"order": "desc"
}
}
]
}
# 查询范围
# range查询
GET map_news/index/_search
{
"query": {
"range": {
"publish_timestamp": {
"gte": "2016-08-24 18:58:00.0",
"lte": "2016-08-24 19:58:00.0"
}
}
}
}
# wildcard查询
# 支持通配符查询
GET map_news/index/_search
{
"_source": {
"includes": ["title"]
},
"query": {
"wildcard": {
"title": {
"value": "pyth*n"
}
}
}
}
# # 组合查询
# bool查询
# 用bool 包括 must should must_not filter 来完成,格式以下
bool:{
"filter":[], 字段的过滤 不参与打分
"must":[], 必须所有都知足
"should":[], 只要知足一个就能够
"must_not":{}, 必须一个都不能知足
}
# 最简单的filter查询
# select * from testjob where salary=20
# 薪资为20的工做
# term 换为 terms 就能够[ ] 查询多个值
get lagou/testjob/_search
{
"query": {
"bool": {
"filter": {
"term": {
"salary": 20
}
}
}
}
}
# 查看分词器解析的结果 ik_max_word 和 ik_smart 2种分词方法
GET _analyze # 分红 python 网络 开发 工程师 工程 师
{
"analyzer": "ik_max_word",
"text": "python网络开发工程师"
}
GET _analyze # 分红 python 网络 开发 工程师
{
"analyzer": "ik_smart",
"text": "python网络开发工程师"
}
# bool过滤查询,能够作组合查询
# select * from testjob where (salary=20 or title=python) and (salary!=30)
#查询薪资等于20k或者是工做为python的工做,排除价格为30k的
{
"query": {
"bool": {
"should": [
{"term": {
"salary": {
"value": "20"
}
}},
{"term": {
"title": {
"value": "python"
}
}}
],
"must_not": [
{"term": {
"salary": {
"value": "30"
}
}}
]
}
}
}
# 嵌套查询
{
"query": {
"bool": {
"should": [
{
"term": {
"salary": {
"value": "20"
}
}
},
{"bool": {
"must": [
{"term": {
"title": {
"value": "python"
}
}},
{
"term": {
"salary": {
"value": "30"
}
}
}
]
}}
],
"must_not": [
{
"term": {
"salary": {
"value": "30"
}
}
}
]
}
}
}
# 查询该字段为null的状况
GET map_news/index/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "content"
}
}
}
}
}
Elasticsearch-dsl
# 取出html标签
from w3lib.html import remove_tags
remove_tags(u'<span>1000</span>')
Es 的 fuzzy 模糊搜索 有必定的纠错性
GET /_search
{
"query": {
"fuzzy": {
"title": {
"value": "linx",
"fuzziness": 2, # 编辑距离 编辑距离要少于等于2步
"prefix_length": 2 # 前面不参数编辑距离计算的词的长度,2 为 li 不参加 编辑计算
}
}
}
}
编辑距离:是指一种字符串之间类似程度的计算方法。
即 两个字符串之间的编辑距离等于使一个字符串变成另外一个字符串而进行的 插入 删除 替换 相邻交换位置 进行操做的最少次数。
好比:ed(“linux”,”linx”)==1 只要删除u就能够了
主要是实现智能提示
Scrapyd 一个有界面能够监控scrapy的好东西