首页 文章 精选 留言 我的

精选列表

搜索[联网搜索API],共10000篇文章
优秀的个人博客,低调大师

文档API

8.2.1.快速上手 文档通过 _index、_type、_id 元数据(metadata),确定 URL 唯一 GET /<_index>/<_type>/<_id> # curl -XPUT 'http://localhost:9200/website/profile/1' -d '{ "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" }' # curl -XGET 'http://localhost:9200/website/profile/1?pretty' { "_index" : "website", "_type" : "profile", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" } } # curl -XPUT 'http://localhost:9200/website/blog/1?pretty' -d '{ > "title": "My first blog entry", > "text": "Just trying this out...", > "date": "2014/01/01" > }' { "_index" : "website", "_type" : "blog", "_id" : "1", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } 后面会详细讲解 PUT与GET的使用方法以及相关参数 8.2.2.写入 PUT/POST 通过 PUT 写入数据 [root@localhost ~]# curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{ > "user" : "kimchy", > "post_date" : "2009-11-15T14:12:12", > "message" : "trying out Elasticsearch" > }' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true} 使用 UUID 替代 _id, 注意使用UUID 必须使用 POST方式提交,不能使用 PUT。 curl -XPOST 'http://localhost:9200/website/news/?pretty' -d '{ "title": "My first news entry", "text": "Just trying this out..." }' { "_index" : "website", "_type" : "news1", "_id" : "AVY0RJrvJRTrBLpmYzBH", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } curl -XGET 'http://localhost:9200/website/news/AVY0RJrvJRTrBLpmYzBH?pretty' 提交后会输出 "_id" : "AVY0RJrvJRTrBLpmYzBH",查询时将此放到放到URL中即可。 8.2.3.获取 GET 通过 GET 读取数据 [root@localhost ~]# curl -XGET 'http://localhost:9200/twitter/tweet/1' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"found":true,"_source":{ "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" }} 8.2.3.1._source 只返回 _source 数据,去掉元数据 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2/_source?pretty' { "title" : "My first news entry", "text" : "Just trying this out..." } 选择字段 _source=title,超过一个字段使用逗号分隔_source=title,text。 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "title" : "My first news entry" } } # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title,text&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "text" : "Just trying this out...", "title" : "My first news entry" } } 8.2.4.检查记录是否存在 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/1 HTTP/1.1 200 OK Content-Type: text/plain; charset=UTF-8 Content-Length: 0 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/100 HTTP/1.1 404 Not Found Content-Type: text/plain; charset=UTF-8 Content-Length: 0 HTTP/1.1 200 OK 表示已经找到你要的数据 HTTP/1.1 404 Not Found 表示数据不存在 8.2.5.删除 Delete 删除 _index curl -XDELETE http://localhost:9200/information/?pretty 删除 _mapping curl -XDELETE http://localhost:9200/information/news/_mapping?pretty 删除对象 curl -XDELETE http://localhost:9200/information/news/1?pretty 8.2.6.参数 8.2.6.1.pretty 格式化 json # curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty' { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } } 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册