当前位置: 首页 > wzjs >正文

北京西站衡水安徽网站建设

北京西站,衡水安徽网站建设,怎么获取客户资源,seo需求文章目录 入门下载Windowslinuxmacos 启动Elasticsearch 和 RDMS 的对比 操作基础语法规则创建索引统一请求 api 前缀DSL语法curl参数说明 删除索引DSL语法curl 判断索引是否存在DSL语法curl 开启/关闭索引开启DSL语法关闭 DSL 语法 索引的别名 Mapping 操作查看 mappingDSL语法…

文章目录

    • 入门
      • 下载
        • Windows
        • linux
        • macos
      • 启动
      • Elasticsearch 和 RDMS 的对比
    • 操作
      • 基础语法规则
      • 创建索引
        • 统一请求 api 前缀
        • DSL语法
        • curl
        • 参数说明
      • 删除索引
        • DSL语法
        • curl
      • 判断索引是否存在
        • DSL语法
        • curl
      • 开启/关闭索引
        • 开启DSL语法
        • 关闭 DSL 语法
      • 索引的别名
    • Mapping 操作
      • 查看 mapping
        • DSL语法
      • 新增 mapping
        • DSL语法
    • 文档的操作
      • 添加文档
        • 新增一条数据 - DSL语法
      • 查询指定索引的所有文档
        • DSL语法
      • 通过 id 查询文档
        • DSL语法
      • 模糊查找
        • DSL语法
      • 通过条件查询文档
        • 通过条件查询 - DSL语法
      • 范围查找
        • DSL语法
      • and 查询
        • DSL语法
      • limit 查找
        • DSL语法
      • limit offset 查找
        • DSL语法
        • 参数说明
      • or 查询
        • DSL语法
    • 删除文档
      • 删除指定 id
        • DSL语法
      • 删除指定条件
        • DSL语法

这是 Elasticsearch 的官方文档。 你可以在这里找到 elasticsearch 的所有文档。

入门

Elasticsearch 是一个基于 Lucene 库的搜索引擎。它提供了一个分布式、支持多租户的全文搜索引擎,具有HTTP Web接口和无模式JSON文档。

下载

注意: ${VERSION} 需替换为指定版本,官方包有的功能只能试用,完整功能需要付费,请仔细阅读官网文档。

Windows
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${VERSION}-windows-x86_64.zip
linux
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${VERSION}-linux-x86_64.tar.gz$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${VERSION}-linux-x86_64.tar.gz.sha512$ shasum -a 512 -c elasticsearch-${VERSION}-linux-x86_64.tar.gz.sha512 $ tar -xzf elasticsearch-${VERSION}-linux-x86_64.tar.gz$ cd elasticsearch-${VERSION}/
macos
$ curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${VERSION}-darwin-x86_64.tar.gz$ curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${VERSION}-darwin-x86_64.tar.gz.sha512 | shasum -a 512 -c - $ tar -xzf elasticsearch-${VERSION}-darwin-x86_64.tar.gz$ cd elasticsearch-${VERSION}/ 

启动

  • 启动 Elasticsearch

    $ ./bin/elasticsearch
    
  • 设置密码

    export ELASTIC_PASSWORD="your_password"
    
  • 测试是否启动成功

    curl --cacert $ES_HOME/config/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200 
    
  • 成功则返回样例如下:

    {"name" : "Cp8oag6","cluster_name" : "elasticsearch","cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA","version" : {"number" : "${VERSION}","build_type" : "tar","build_hash" : "f27399d","build_flavor" : "default","build_date" : "2016-03-30T09:51:41.449Z","build_snapshot" : false,"lucene_version" : "9.10.0","minimum_wire_compatibility_version" : "1.2.3","minimum_index_compatibility_version" : "1.2.3"},"tagline" : "You Know, for Search"
    }
    

Elasticsearch 和 RDMS 的对比

RDMSelasticsearch
数据库(database)索引(index)
表(table)类型(type)
行(row)文档(document)
列(column)字段(field)
表结构映射
索引全文索引
SQL查询DSL
SELECT * FROM tablenameGET http://…
UPDATE table SETPUT http://…
DELETEDELETE http://…

操作

基础语法规则

$ curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'
  • VERB HTTP 方法:GET, POST, PUT, HEAD, DELETE
  • PROTOCOL:http 或者 https 协议(只有在 Elasticsearch 前面有 https 代理的时候可用)
  • HOST:Elasticsearch 集群中的任何一个节点的主机名,如果是在本地的节点,那么就叫 localhost
  • PORT:Elasticsearch HTTP 服务所在的端口,默认为 9200
  • PATH API 路径(例如_count 将返回集群中文档的数量),PATH:可以包含多个组件,例如_cluster/stats 或者_nodes/stats/jvm
  • QUERY_STRING:一些可选的查询请求参数,例如?pretty 参数将使请求返回更加美观易读的 JSON 数据
  • BODY:一个 JSON 格式的请求主体(如果请求需要的话)

创建索引

统一请求 api 前缀
http://localhost:9200/
DSL语法
PUT /user_info
{"settings": { "number_of_replicas": 1, "number_of_shards": 1 },"mappings": {"properties": {"id": { "type": "long", "index": true },"username": { "type": "keyword", "index": true },"nickname": { "type": "keyword", "index": true },"password": { "type": "keyword", "index": false },"age": { "type": "integer", "index": true },"info": { "type": "text", "index": true },"remark": { "type": "text", "index": true }}}
}
curl
curl -XPUT "http://localhost:9200/user_info" -H 'Content-Type: application/json' -d'{ "settings": { "number_of_replicas": 1, "number_of_shards": 1 }, "mappings": { "properties": { "id": { "type": "long", "index": true }, "username": { "type": "keyword", "index": true }, "nickname": { "type": "keyword", "index": true }, "password": { "type": "keyword", "index": false }, "age": { "type": "integer", "index": true }, "info": { "type": "text", "index": true }, "remark": { "type": "text", "index": true } } } }'
参数说明
  • settings: 设置索引的信息
  • number_of_shards: 每个索引的主分片数,一旦索引创建后,无法修改此配置
  • number_of_replicas: 每个主分片的副本数,此配置可随时修改
  • mappings: 索引映射定义
  • properties: 字段定义。使用 JSON 配置,键为字段名称(自定义),值为嵌套 JSON,其中 type 指定字段的类型

其他参数很多,请参考官网资料

删除索引

DSL语法
DELETE /user_info
curl
curl -XDELETE "http://localhost:9200/user_info"

判断索引是否存在

DSL语法
# 查看索引是否存在
HEAD /user_info
curl
# 查看索引是否存在
curl -XHEAD "http://localhost:9200/user_info"

开启/关闭索引

开启DSL语法
POST /user_info/_open

curl

curl -XPOST "http://localhost:9200/user_info/_open"
关闭 DSL 语法
POST /user_info/_close

curl

curl -XPOST "http://localhost:9200/user_info/_close"

索引的别名

  • 添加别名 DSL 语法
POST /user_info/_alias/user1
curl -XPOST "http://localhost:9200/user_info/_alias/user1"
  • 删除别名DSL语法
DELETE /user_info/_alias/user1
curl -XDELETE "http://localhost:9200/user_info/_alias/user1"
  • 查看别名DSL语法
GET /_alias/user1
curl -XGET "http://localhost:9200/_alias/useraa"

Mapping 操作

类似修改数据库中列的操作

查看 mapping

DSL语法
GET /user_info/_mapping

curl -XGET "http://localhost:9200/user_info/_mapping"

新增 mapping

DSL语法
PUT /user_info/_mapping
{"properties":{"sex":{ "type":"keyword" }}
}

curl -XPUT "http://localhost:9200/user_info/_mapping" -H 'Content-Type: application/json' -d'{ "properties":{ "sex":{ "type":"keyword" } } }'

注意: 需要注意的是字段映射只能增加,不能更改删除

文档的操作

添加文档

新增一条数据 - DSL语法
POST /user_info/_doc/1
{"id":1,"username":"username","password":"123456","nickname":"nickname","age":18,"info":"一些个人相关的介绍","remark":"备注信息","sex":"男"
}

curl -XPOST "http://localhost:9200/user_info/_doc/1" -H 'Content-Type: application/json' -d'{ "id":1, "username":"username", "password":"123456", "nickname":"nickname", "age":18, "info":"一些个人相关的介绍", "remark":"备注信息", "sex":"男" }'

查询指定索引的所有文档

类似数据库中的 select * from user_info;

DSL语法
GET /user_info/_search
{"query": {"match_all": {}}
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "query": { "match_all": {} } }'

通过 id 查询文档

类似数据库中的 select * from user_info where id = 1;

DSL语法
GET /user_info/_doc/1

curl -XGET "http://localhost:9200/user_info/_doc/1"

模糊查找

类似数据库中的模糊查询 select * from user_info where info like '%人%';

DSL语法
GET /user_info/_search
{"query": { "match": { "info": "人" } }
}

通过条件查询文档

类似数据库中的 select * from user_info where username = 'username';

通过条件查询 - DSL语法
GET /user_info/_search
{"query": {"bool": {"must": [ { "term": { "username": "username" } } ]}}
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "query": { "bool": { "must": [ { "term": { "username": "username" } } ] } } }'

范围查找

类似数据库中的范围查询 select * from user_info where age between 18 and 30;

DSL语法
GET /user_info/_search
{"query": {"range": {"age": {"gt": 18,"lt": 30}}}
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "query": { "range": { "age": { "gt": 18, "lt": 30 } } } }'

and 查询

类似数据库中的 and 查询 select * from user_info where age > 18 and sex = '男';

DSL语法
GET /user_info/_search  
{  "query": {"bool": {"must": [{ "range": { "age": { "gt": 18 } } },{ "term": { "sex": "男" } }]   }}
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "query": { "bool": { "must": [ { "range": { "age": { "gt": 17 } } }, { "term": { "sex": "男" } } ] } } }'

limit 查找

类似数据库中的 limit 查询 select * from user_info limit 10;

DSL语法
GET /user_info/_search  
{  "size": 10,  "query": {  "match_all": {}     }
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "size": 1, "query": { "match_all": {} } }'

limit offset 查找

类似数据库中的 limit 查询 select * from user_info limit 0,10;

DSL语法
GET /user_info/_search  
{  "size": 2,  "from": 1,  "query": {  "match_all": {}  }  
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "size": 2, "from": 1, "query": { "match_all": {} } }'
参数说明
  • size: 10 表示我们想要返回的结果数量是10条
  • from: 20 表示我们想要从结果集中的第21条记录开始返回(因为偏移是从0开始的)
  • query: {"match_all": {}} 是一个匹配所有文档的查询,因为我们没有特定的查询条件,只是想要分页结果

or 查询

类似数据库中的 or 查询 select * from user_info where age > 18 or sex = '男';

DSL语法
GET /user_info/_search
{"query": {"bool": {"should": [{"range": {"age": { "gt": 18 }}},{"term": { "sex": "男" }}]}}
}

curl -XGET "http://localhost:9200/user_info/_search" -H 'Content-Type: application/json' -d'{ "query": { "bool": { "should": [ { "range": { "age": { "gt": 18 } } }, { "term": { "sex": "男" } } ] } } }'

删除文档

删除指定 id

类似数据库中的 delete 查询 delete from user_info where id = 3;

DSL语法
# 删除文档
DELETE /user_info/_doc/3

# 删除文档
curl -XDELETE "http://localhost:9200/user_info/_doc/3"

删除指定条件

类似数据库中的 delete 查询 delete from user_info where age > 18;

DSL语法
POST /user_info/_delete_by_query
{"query": {"range": { "age": { "gt": 18 } }}
}

curl -XPOST "http://localhost:9200/user_info/_delete_by_query" -H 'Content-Type: application/json' -d'{"query":{"range":{"age":{"gt":18}}}}'

文章转载自:

http://OzNY7lFT.qfgxk.cn
http://cT2wj459.qfgxk.cn
http://2hlcfZUS.qfgxk.cn
http://dTjRSdNU.qfgxk.cn
http://glPCRdtC.qfgxk.cn
http://SyFQ6DJY.qfgxk.cn
http://ZIdBhPyA.qfgxk.cn
http://1cE2bdjd.qfgxk.cn
http://8KBHcUhC.qfgxk.cn
http://NkZa2tF5.qfgxk.cn
http://XQukw6gh.qfgxk.cn
http://ONwTCtIO.qfgxk.cn
http://9hBdrBtR.qfgxk.cn
http://QicSBwFn.qfgxk.cn
http://frXQIOTM.qfgxk.cn
http://7JLMZOIM.qfgxk.cn
http://EcVJW1QC.qfgxk.cn
http://IKsN1knR.qfgxk.cn
http://mNGv6N9G.qfgxk.cn
http://8eDVTpIe.qfgxk.cn
http://jW3Txo44.qfgxk.cn
http://fPwYEUI6.qfgxk.cn
http://A0kDtVuT.qfgxk.cn
http://MoqytuCP.qfgxk.cn
http://j6rx4xMJ.qfgxk.cn
http://vmq8GOnQ.qfgxk.cn
http://2xHYsDaY.qfgxk.cn
http://VkbEVSQV.qfgxk.cn
http://zPDVTM5r.qfgxk.cn
http://PCbgHhNj.qfgxk.cn
http://www.dtcms.com/wzjs/716358.html

相关文章:

  • 做网站开发背景企业网站建设的成本构成
  • 如何给网站做右侧导航广州富邦物流网站建设
  • 五金外贸网站容桂商城网站建设
  • 南昌网站建设费用自主设计网站
  • 地税局网站建设情况汇报wordpress侧边栏浮动
  • 网站点击个人网站备案名字不同
  • 个人可以做外贸网站吗seo搜索引擎优化师
  • 中天会展中心网站建设方案新开家政如何做网站
  • 设计好的制作网站qq小程序权限设置
  • 旅游网站建设的总结网站空间登录
  • 怎么制作钓鱼网站wordpress 显示错误
  • 常用python编程软件优化搜索引擎的方法
  • 台州网站搭建广告投放基础知识
  • 百度网站怎样优化排名网站搜索引擎优化技术
  • 东莞知名网站优化公司网页制作步骤教程
  • 商业网站建设案例课程房子装修风格大全2021新款
  • 做pc端网站价位h5网站开发定制
  • 网站之间的差异做app需要网站吗
  • 临安做企业网站安徽津城建设工程有限公司网站
  • 网站开发去哪里找番禺人才网车床工铣床工招聘
  • 网站空间没有续费需要证书的建筑公司网站
  • 在哪个网站上做苗木生意好些ip代理免费
  • 网站备案当面核验拍摄照片霍山做网站
  • 怎么在百度首页做网站私域流量管理工具
  • 建网站程序网站建设 豫icp备
  • 潍坊网站建设维护河源网站建设多少钱
  • 网站设计公司网站设计0元开网店
  • 推荐几个做网站比较好的公司网站服务器要求
  • 襄樊做网站论坛怎样发帖推广
  • 广西注册公司网站公司网站建设费计入哪个科目