hello cc

ES操作记录

Posted on 2015-12-02 11:51  星际海盗  阅读(1675)  评论(0)    收藏  举报

很好玩的es,研究研究。

内容摘自:《elasticsearch开发》一书

ES蛮有趣,不错!

一: 一些概念

1. es特点:提供一个全文检索的功能库。它非常快速,可扩展,并提供不同语言的分析能力。

2.常见名词:

1) 索引(index): 是Elasticsearch对逻辑数据的逻辑存储,所以它可以分为更小的部分。你可以把
       索引看成关系型数据库的表。然而,索引的结构是为快速有效的全文索引准备的,特别是它不存
  储原始值。如果你知道MongoDB,可以把Elasticsearch的索引看成MongoDB里的一个集合。如果
  你熟悉CouchDB,可以把索引看成CouchDB数据库索引。Elasticsearch可以把索引存放在一台机器
  或者分散在多台服务器上,每个索引有一或多个分片 (shard),每个分片可以有多个副本 (replica)

2) 节点(node): Elasticsearch可以作为一个独立的单个搜索服务器,也可以运行在许多互相合作的服务器上,

      这些服务器称为集群(cluster),形成集群的每个服务器称为节点(node)。

3) 文档(document): 索引和搜索时使用的主要数据载体,包含一个或多个存有数据的字段

4) 字段(field): 文档的一部分,包含名称和值两部分。

5) 词(term): 一个搜索单元,表示文本中的一个词。

6) 标记(token):表示在字段文本中出现的词,由这个词的文本、开始和结束偏移量以及类型组成

7)  Elasticsearch处理许多节点。集群的状态由时光之门控制,..

 

二:一些操作

1. 新建文档:

curl -XPUT http://localhost:9200/blog/article/1 -d '{"title": "New version of
Elasticsearch released!", content": "Version 1.0 released today!", "tags": ["announce",
"elasticsearch", "release"] }'
  成功返回文档基本信息

如果手动不指定标示符的话,es会自己随机创建一个很恶心的标示符。

 

python operate ES

es = Elasticsearch([{'host': '192.168.220.241','port':9200}])
es = Elasticsearch(['192.168.220.241:9200'])

es = Elasticsearch(['http://192.168.220.241:9200'])

2. 索引文档:

curl -XGET http://localhost:9200/blog/article/1
或者直接访问:

http://localhost:9200/blog/article/1

注意:

1) blog是上一步中新建的索引,article是索引的类型,后面的1是索引的标示符,如下图中,在一个索引中创建了两个文档,每个文档有不同的标示符。

test-index
test-type
1
 
2015-11-25T13:26:22.540253
11111111111111111122222222222222222223333333333333
test-index
test-type
2
 
2015-11-25T13:27:06.210413
zzzzzzzzzzzzzzxxxxxxxxxxxxxxccccccccccccccc
 

3. 请求内容

es.get(index='sw', doc_type='people', id=65)


4. 搜索内容

es.search(index="vulns", body={"query": {"prefix" : { "title" : "xss" }}})

es.search(index='logstash-2015.08.20', q='domain:baidu AND server:"nginx"')
常用参数
  • index - 索引名
  • q - 查询指定匹配 使用Lucene查询语法
  • from_ - 查询起始点  默认0
  • doc_type - 文档类型
  • size - 指定查询条数 默认10,   max=900000000
  • field - 指定字段 逗号分隔
  • sort - 排序  字段:asc/desc
  • body - 使用Query DSL
  • scroll - 滚动查询
 

 三:安装方面

elasticsearch集群搭建实例   http://www.cnblogs.com/dennisit/p/4132269.html

centos7安装elasticsearch  http://www.centoscn.com/image-text/install/2016/0812/7770.html

 

四:其他

搜索引擎选择: Elasticsearch与Solr    http://www.cnblogs.com/chowmin/articles/4629220.html

Elasticsearch、MongoDB跟Hadoop比较  http://www.myexception.cn/go/1885143.html

 

web缓存技术总结    http://blog.csdn.net/simongyley/article/details/23353619

Web前后端缓存技术    http://blog.csdn.net/LeeSirbupt/article/details/54409931

 

hello man