Sense

为了方便、直观的使用es的REST Api,我们可以使用sense。Sense是Chrome浏览器的一个插件,使用简单。

如图:

Sense安装:

https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo

或者直接去chrome网上应用店搜索安装。


CRUD

URL的格式:

http://localhost:9200/<index>/<type>/[<id>]

其中index、type是必须提供的。

id是可选的,不提供es会自动生成。

index、type将信息进行分层,利于管理。index可以理解为数据库,type理解为数据表。

补一张图(0211)

The type called another_type and the index called another is shown in order to emphasize that Elasticsearch is multi-tenant, by which we mean that a single server can store multiple indexes and multiple types.

上面解释了“多租户”!

索引文档(Create、update)

首先我们塞入一条数据,命令如下:

curl -XPUT "http://localhost:9200/movies/movie/1" -d'
{
"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972
}'

-d代表一个json格式的对象,这里是一部电影数据。

运行结果如下:

通过默认查询我们可以查询到刚才添加的数据,如下:

下面我们来修改这条数据,添加电影的类型,如下:

curl -XPUT "http://localhost:9200/movies/movie/1" -d'
{
"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972,
"genres": ["Crime", "Drama"]
}'

再查询可以发现该数据多了一个字段:genres。

通过id进行查询(getting by id)

curl -XGET "http://localhost:9200/movies/movie/1" -d''

删除文档(deleting document)

curl -XDELETE "http://localhost:9200/movies/movie/1" -d''

再通过getting by id,返回:

检索(search)

为了检索我们先多添加几篇文档:

curl -XPUT "http://localhost:9200/movies/movie/1" -d'
{
"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972,
"genres": ["Crime", "Drama"]
}' curl -XPUT "http://localhost:9200/movies/movie/2" -d'
{
"title": "Lawrence of Arabia",
"director": "David Lean",
"year": 1962,
"genres": ["Adventure", "Biography", "Drama"]
}' curl -XPUT "http://localhost:9200/movies/movie/3" -d'
{
"title": "To Kill a Mockingbird",
"director": "Robert Mulligan",
"year": 1962,
"genres": ["Crime", "Drama", "Mystery"]
}' curl -XPUT "http://localhost:9200/movies/movie/4" -d'
{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama", "War"]
}' curl -XPUT "http://localhost:9200/movies/movie/5" -d'
{
"title": "Kill Bill: Vol. 1",
"director": "Quentin Tarantino",
"year": 2003,
"genres": ["Action", "Crime", "Thriller"]
}' curl -XPUT "http://localhost:9200/movies/movie/6" -d'
{
"title": "The Assassination of Jesse James by the Coward Robert Ford",
"director": "Andrew Dominik",
"year": 2007,
"genres": ["Biography", "Crime", "Drama"]
}'

  

最好再参考下:ElasticSearch's query DSL

{
"query": {
//Query DSL here
}
}

  

--基本的文本检索

curl -XPOST "http://localhost:9200/_search" -d'
{
"query": {
"query_string": {
"query": "kill"
}
}
}'

  

--指定字段进行检索

curl -XPOST "http://localhost:9200/_search" -d'
{
"query": {
"query_string": {
"query": "ford",
"fields": ["title"]
}
}
}'

fields默认为"_all" 。

--过滤(filtering)

curl -XPOST "http://localhost:9200/_search" -d'
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "drama"
}
},
"filter": {
"term": { "year": 1962 }
}
}
}
}'

  

详细api,参考:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html

部分内容摘抄自:

http://joelabrahamsson.com/elasticsearch-101/


query VS filter

摘录一张有意思的ppt。

最新文章

  1. AliSQL的编译使用
  2. JQuery EasyUI DataGrid列表所见所得随意导出excel
  3. 如何在github下载开源项目到本地(Coding iOS 客户端为例)
  4. shell学习之路:shell基础大全2
  5. hdu 1279 验证角谷猜想
  6. unity,standalone下自定义分辨率不起作用的解法
  7. MySQL的存储引擎整理
  8. C语言数据输入与输出
  9. C# 匿名方法 委托 Action委托 Delegate委托
  10. js中 ===与==
  11. delphi cmd(4个例子都是通过管道取得)
  12. 2.7 if应用:猜拳游戏
  13. COMP9021 PRINCIPLES OF PROGRAMMING
  14. 先装IIS后装.Net Framework
  15. Nlog 简单的快速攻略
  16. 【规范】前端编码规范——jquery 规范
  17. 《C#从现象到本质》读书笔记(三)第3章C#类型基础(下)
  18. 奇淫怪巧之在Delphi中调用不申明函数
  19. kolla-ansible部署多节点OpenStack-Pike
  20. 对类型“DevExpress.Xpf.Grid.GridControl”的构造函数执行符合指定的绑定约束的调用时引发了异常。

热门文章

  1. [LeetCode&amp;Python] Problem 387. First Unique Character in a String
  2. 前端解析websocket数据问题
  3. select标签(下拉菜单和列表)
  4. Docker第一个应用:Hello World
  5. Elasticsearch Docker环境下安装
  6. 【BZOJ1202】【HNOI2005】狡猾的商人
  7. ios存储图片注意
  8. 写一个小程序实现win系统定时锁屏
  9. dup等复制文件描述符函数
  10. BinaryReader 自己写序列化