搜索引擎搭建

一、java环境安装

二、elasticsearch-rtf安装(github)

https://github.com/search?q=elasticsearch-rtf

三、elasticsearch-head安装(github)

需要安装node.js

更改安全策略,否则elassearch-head不能连接elasticsearch

elasticsearch-rtf\config\elasticsearch.yml

http.cors.enabled: true 
http.cors.allow-origin: "*"
node.master: true
node.data: true

四、安装kibana

https://artifacts.elastic.co/downloads/kibana/kibana-5.1.1-windows-x86.zip

五、elasticsearch中的一些概念

集群:一个或多个节点组织在一起。

节点:一个节点是集群中的一个服气,由一个名字来标识,默认是一个随机的漫画角色的名字。

分片:将索引划分为多份的能力,允许水平分割和扩展容量,多个分片响应请求,提高性能和吞吐量。

副本:创建分片的一份或多份的能力,在一个节点失败其余节点可以顶上

elasticsearchmysql
index(索引)数据库
type(类型)
documents(文档)
fields

六、数据的curd

创建索引

PUT lagou
{
  "settings": {
    "index":{
      "number_of_shards":5, 分片数,,分片数量不能修改
      "number_of_replicas":1 副本数
    }
  }
}

获取索引

GET lagou/_settings

更新索引:

PUT lagou/_settings
{
  "number_of_replicas": 2
}

添加文档:

PUT lagou/job/1
{
  "title":"python开发",
  "city":"北京"
}

 

#会自动生成id值
PUT lagou/job/
{
  "title":"java开发",
  "city":"北京"
}

获取文档:

GET lagou/job/1

GET lagou/job/1?_source=title

修改文档:
 

覆盖
PUT lagou/job/1
{
  "title":"python开发",
  "city":"北京",
  "salary":15000
}

修改某个字段
POST lagou/job/1/_update
{
  "doc":{
    "comments":"扁平化"
  }
}
#删除文档
DELETE lagou/job/1
#删除索引
DELETE lagou

七、elasticsearch的映射

映射:创建索引的时候,可以预先定义字段的类型以及相关属性。

string类型:text,keyword

数据类型:long,integer,short,byte,double,float

日期类型:date

bool类型:boolean

binary类型:binary

复杂类型:object,nested

geo类型:geo-point,geo-shape

专业类型:ip,competion

PUT lagou
{
  "mappings": {
    "job":{
      "properties": {
        "title":{
          "store":true,
          "type":"text",
          "analyzer": "ik_max_word"  分析器
        },
        "company_name":{
          "store": true,
          "type": "keyword"  keyword不会被分析器分词
        }, 
        "desc":{
          "type": "text"
        },
        "comments":{
          "type": "integer"
        },
        "add_time":{
          "type": "date",
          "format": "year_month_day"   格式
        }
      }
    }
  }
}

八、查询

基本查询:使用elasticsearch内置查询条件进行查询
组合查询:把多个查询组合在一起进行复合查询
过滤:通过filter过滤

添加数据

……
POST lagou/job/
{
  "title":"python开发",
  "company_name":"京东",
  "desc":"熟练Python",
  "comments":4,
  "add_time":"2017-4-15"
}
……

match查询

GET lagou/_search
{
  "query": {
    "match": {
      "title": "开发"
    }
  }
}

term查询

GET lagou/_search
{
  "query": {
    "term": {
      "title": "python全栈开发"
    }
  }
}

不对搜索进行分词,完全匹配才会出现结果。

terms查询

GET lagou/_search
{
  "query": {
    "terms": {
      "title":["python","开发","全栈"]
    }
  }
}

对多个关键词进行查询

控制返回数量

GET lagou/_search
{
  "query": {
    "terms": {
      "title":["python","开发","全栈"]
    }
  },
"from":0,
"size": 2
}

组合查询

GET lagou/_search
{

    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "title": "python"
                    }
                }
            ],
            "filter": {"match":{"company_name":"美团"}}, 
            "must_not": [ ],
            "should": [ ]
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值