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。

elasticsearch 口水篇(2)CRUD Sense的更多相关文章

  1. elasticsearch 口水篇(4)java客户端 - 原生esClient

    上一篇(elasticsearch 口水篇(3)java客户端 - Jest)Jest是第三方客户端,基于REST Api进行调用(httpClient),本篇简单介绍下elasticsearch原生 ...

  2. elasticsearch 口水篇(6) Mapping 定义索引

    前面我们感觉ES就想是一个nosql数据库,支持Free Schema. 接触过Lucene.solr的同学这时可能会思考一个问题——怎么定义document中的field?store.index.a ...

  3. elasticsearch 口水篇(8)分词 中文分词 ik插件

    先来一个标准分词(standard),配置如下: curl -XPUT localhost:9200/local -d '{ "settings" : { "analys ...

  4. elasticsearch 口水篇(7) Eclipse中部署ES源码、运行

    ES源码可以直接从svn下载 https://github.com/elasticsearch/elasticsearch 下载后,用Maven导入(import——>Existing Mave ...

  5. elasticsearch 口水篇(3)java客户端 - Jest

    elasticsearch有丰富的客户端,java客户端有Jest.其原文介绍如下: Jest is a Java HTTP Rest client for ElasticSearch.It is a ...

  6. elasticsearch 口水篇(1) 安装、插件

    一)安装elasticsearch 1)下载elasticsearch-0.90.10,解压,运行\bin\elasticsearch.bat (windwos) 2)进入http://localho ...

  7. elasticsearch 口水篇(5)es分布式集群初探

    es有很多特性,分布式.副本集.负载均衡.容灾等. 我们先搭建一个很简单的分布式集群(伪),在同一机器上配置三个es,配置分别如下: cluster.name: foxCluster node.nam ...

  8. elasticsearch 口水篇(9)Facet

    FACET 1)Terms Facet { "query" : { "match_all" : { } }, "facets" : { &q ...

  9. ELK 学习笔记之 elasticsearch基本概念和CRUD

    elasticsearch基本概念和CRUD: 基本概念: CRUD: 创建索引: curl -XPUT 'http://192.168.1.151:9200/library/' -d '{" ...

随机推荐

  1. ccf-170902-公共钥匙盒(模拟)

    这是一道典型的模拟题 首先我们把借钥匙和还钥匙切分成两个事件 保存于两个数组中 然后我对还钥匙的活动按照时间发生次序和还得钥匙序号排序,即按照题意对事件发生的次序排序 最后按照时间的进行 一个一个进行 ...

  2. NYOJ 47:过河问题(思维)

    47-过河问题 内存限制:64MB 时间限制:1000ms 特判: No 通过数:6 提交数:10 难度:5 题目描述: 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边.如果不借助手电筒的话 ...

  3. Thread sleep() wait()

    学艺不精,先总结一下两者的区别: 对比项 wait sleep 类所属 Object Thread,static方法 使用 在synchronised block中(包括notify,notifyAl ...

  4. 2017.4.4 TCP/IP协议栈

    OSI和TCP/IP的各层协议总结: TCP/IP在封装和传输数据时,各层所做的工作:

  5. 自我复制的3D打印机

    RepRap 是人类历史上第一部可以自我复制型的机器. https://reprap.org/wiki/RepRap RepRap 是一部可以生成塑料实物的免费桌面型 3D 打印机.由于 RepRap ...

  6. Oracle 11g direct path read 等待事件的理解

    在Oracle 11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读的,所以不存在di ...

  7. python基础(八)——多线程

    [root@bogon python]# cat test.py #!/usr/bin/ptyhon import thread import time def print_time(threadNa ...

  8. gcc的编译属性和选项

    1.指定内存默认对其参数: __attribute__((packed)):按一字节对其__attribute__((aligned(n))):从此之后默认按n字节对其 例如: struct stu ...

  9. Java Runnable与Callable区别

    接口定义 #Callable接口 public interface Callable<V> { V call() throws Exception; } #Runnable接口 publi ...

  10. Jmeter分离登录事务的另一种方式

    最近,遇到了一个困扰很多人的问题. 情景如下: 业务流程:登录一个网站,反复进行充值. 通常的做法是使用jmeter对登录和充值的接口进行反复的执行: 但是实现的方法却不能完美的贴合业务流程. 并且, ...