大家在写QueryDSL的时候,要特别注意参数,比如今天我就碰到了一个关于_cache的问题 由于使用自己写的QueryBuilder来生成QueryDSL查询语句,所以有些参数虽然没有指定,但是默认带上了,但有些情况下不注意就会出现问题。 如下例: 阅读这篇文章的其余部分 »
cn域名解锁就是慢啊,
以后ES中文文档都放这里了:http://doc.elasticsearch.cn
下面是已完成的部分链接:
安装:http://doc.elasticsearch.cn/guide/reference/setup/
配置:http://doc.elasticsearch.cn/guide/reference/setup/configuration.html
API接口说明:http://doc.elasticsearch.cn/guide/reference/api/
QueryDSL查询:http://doc.elasticsearch.cn/guide/reference/query-dsl/
Mapping:http://doc.elasticsearch.cn/guide/reference/mapping/
索引模块:http://doc.elasticsearch.cn/guide/reference/index-modules/store.html
事务日志:http://doc.elasticsearch.cn/guide/reference/index-modules/translog.html
...
文档比较多,招志愿者一起翻译。
基于私有云的elasticsearch批量部署
阅读这篇文章的其余部分 »
本文来自: 基于私有云的elasticsearch批量部署
elasticsearch里面的search_type共有如下几种:
The type of the search operation to perform. Can be
dfs_query_then_fetch,
dfs_query_and_fetch,
query_then_fetch,
query_and_fetch. 【removed,since:http://groups.google.com/group/elasticsearch/browse_thread/thread/7aa5ea823afb499/d9e3cf3a1e1f6964】
Defaults to query_then_fetch.
form google group:“
You get proper sorted results when you use query_then_fetch (across all top
"size" results), if you use query_and_fetch, then each shard return the size
requested hits, and then they are sorted between them.
”
直接看代码里面吧,里面都有注释。
public enum SearchType { /** * Same as {@link #QUERY_THEN_FETCH}, except for an initial scatter phase which goes and computes the distributed * term frequencies for more accurate scoring. */ DFS_QUERY_THEN_FETCH((byte) 0), /** * The query is executed against all shards, but only enough information is returned (not the document content). * The results are then sorted and ranked, and based on it, only the relevant shards are asked for the actual * document content. The return number of hits is exactly as specified in size, since they are the only ones that * are fetched. This is very handy when the index has a lot of shards (not replicas, shard id groups). */ QUERY_THEN_FETCH((byte) 1), /** * Same as {@link #QUERY_AND_FETCH}, except for an initial scatter phase which goes and computes the distributed * term frequencies for more accurate scoring. */ DFS_QUERY_AND_FETCH((byte) 2), /** * The most naive (and possibly fastest) implementation is to simply execute the query on all relevant shards * and return the results. Each shard returns size results. Since each shard already returns size hits, this * type actually returns size times number of shards results back to the caller. */ QUERY_AND_FETCH((byte) 3), /** * Performs scanning of the results which executes the search without any sorting. * It will automatically start scrolling the result set. */ SCAN((byte) 4), /** * Only counts the results, will still execute facets and the like. */ COUNT((byte) 5); /** * The default search type ({@link #QUERY_THEN_FETCH}. */ public static final SearchType DEFAULT = QUERY_THEN_FETCH; }
Diving Into ElasticSearch(10)精确控制之Routing使用
<Date: 2011-10-22> <Category: Diving Into ElasticSearch> 发表评论前面一篇介绍parent-child的使用,我们来回顾一下:
1.先建好mapping和索引几条数据
curl -XPUT 'http://localhost:9200/news/comment/_mapping' -d '{ "comment" : { "_parent" : { "type" : "hot" } }}' curl -XPUT 'http://localhost:9200/news/comment/1?parent=1' -d '{ "uname" : "凤凰网安徽省六安市网友", "content" : "河南警方的话没人信"}' curl -XPUT 'http://localhost:9200/news/comment/2?parent=1' -d '{ "uname" : "凤凰网湖北省武汉市网友", "content" : "没有监督权\n没有调查\n一切当然只能是谣言"}' curl -XPUT 'http://localhost:9200/news/comment/3?parent=1' -d '{ "uname" : "ladygaga", "content" : "双下肢不活动,存在废用性肌肉萎缩。请问,这个是怎么做到的?"}' curl -XPUT 'http://localhost:9200/news/comment/4?parent=1' -d '{ "uname" : "medcl", "content" : "额"}'
2.获取一下这几条数据看看
http://localhost:9200/news/comment/1
结果:
{"_index":"news","_type":"comment","_id":"1","_version":1, "_source" : { "uname" : "凤凰网安徽省六安市网友", "content" : "河南警方的话没人信"}}
没有问题,我们再试试后面的
http://localhost:9200/news/comment/2
结果:
HTTP/1.1 404 Not Found Access-Control-Allow-Origin: * Content-Type: application/json; charset=UTF-8 Content-Length: 45 {"_index":"news","_type":"comment","_id":"2"}
嘿嘿,发现了么,居然是404,你可以继续试试后面的id为3的也是404,id为4的可以出来
试试:http://localhost:9200/news/comment/2?parent=1(索引时的path)
HTTP/1.1 404 Not Found
哈哈,貌似不行o.(ps:其实kimchy可以实现这个url pattern,但是目前没有)
那正确的方式是怎样的呢?
http://localhost:9200/news/comment/1?routing=1 http://localhost:9200/news/comment/1?routing=2 http://localhost:9200/news/comment/1?routing=3 http://localhost:9200/news/comment/1?routing=4
答案就在routing,ES帮助:http://www.elasticsearch.org/guide/reference/mapping/routing-field.html
使用我写的partial_update插件也是支持routing的,如下:
curl -XPUT 'http://localhost:9200/news/comment/4/_update?parent=1' -d '{ "content" : "连老卡都不斗争了,难道真的登船去了吗?"}'
结果:
curl -XGET http://localhost:9200/news/comment/4?routing=1 {"_index":"news","_type":"comment","_id":"4","_version":2, "_source" : {"content":"连老卡都不斗争了,难道真的登船去了吗?","uname":"medcl"}}
发散一下,parent=2试试:
curl -XPUT 'http://localhost:9200/news/comment/4/_update?parent=2' -d '{ "content" : "周公使管叔监殷"}'
结果:
curl -XGET http://localhost:9200/news/comment/4?routing=2 {"_index":"news","_type":"comment","_id":"4","_version":1, "_source" : {"content":"周公使管叔监殷","uname":"medcl"}} curl -XGET http://localhost:9200/news/comment/4?routing=1 {"_index":"news","_type":"comment","_id":"4","_version":2, "_source" : {"content":"连老卡都不斗争了,难道真的登船去了吗?","uname":"medcl"}}
很明细,/news/comment/4存在两条记录,routing的出现,使ES的id的唯一性丢失了,并且删除索引记录的时候也必须带上routing才行,此外,查询的结果中可能会出现重复的_id。
curl -XDELETE http://localhost:9200/news/comment/4?routing=1 curl -XDELETE http://localhost:9200/news/comment/4?routing=2
再看看查询的操作,查询的时候可以指定routing,默认不区分routing,即全部扫描:
curl -XGET http://localhost:9200/news/comment/_search?q=* curl -XGET http://localhost:9200/news/comment/_search?q=*&routing=3
总之,一旦你决定使用routing,你必须保证对这些routing做到心中有数。
Diving Into ElasticSearch(9)Parent-Child特性使用
<Date: 2011-10-19> <Category: Diving Into ElasticSearch> 发表评论介绍下ElasticSearch里Parent-Child特性的使用。
//首先创建一系列新闻的索引,这里我们将hot类型作为parent-chid关系里面的parent。
curl -XPUT 'http://localhost:9200/news/hot/1' -d '{ "uname" : "medcl", "content" : "河南警方:“南阳老板遭逼供致残与狗同笼”纯属谎言"}' curl -XPUT 'http://localhost:9200/news/hot/2' -d '{ "uname" : "medcl", "content" : "马英九打两岸牌反制绿营"}' curl -XPUT 'http://localhost:9200/news/hot/3' -d '{ "uname" : "medcl", "content" : "专题:中共十七届六中全会公报"}'
Diving Into ElasticSearch(8)Mapping&Schema
<Date: 2011-09-27> <Category: Diving Into ElasticSearch> 4 条评论前面应该介绍过ES是Schema Free,但是Schema Free不是说没有Schema,和Solr一样,ElasticSearch也可以设置document的schema,ES里的名字叫Mapping,其实无非就是设置document包含哪些Field,然后对每一个Field个性化的设置索引类型,是否存储,以及设置索引分析器和查询使用的分析器,Es和Solr相比有一个我认为最好的特性:就是支持Object类型,你可以像操作对象一样对对象的某个属性进行索引和查询,简单演示如下:
阅读这篇文章的其余部分 »
地址:https://github.com/medcl/ElasticSearch.PartialUpdate
是否碰到过因为需要修改索引中某个字段,而需要将整个索引文档进行重建,是不是很麻烦啊,昨天弄了个插件,就是方便索引文档局部更新的,使用说明如下:
1.先下载插件,解压到ES的plugin目录:
elasticsearch/plguin/es-partial-update/
2.试一把
先索引一个文档吧
curl -XDELETE http://localhost:9200/index/type1/1/ curl -XPOST http://localhost:9200/index/type1/1/ -d'{"name":"medcl","blog":"http://log.medcl.net"}' {"ok":true,"_index":"index","_type":"type1","_id":"1","_version":1}
执行修改操作,添加一个字段,修改一个字段
curl -XPOST http://localhost:9200/index/type1/1/_update -d'{"name":"medcl?","time":"2011-1-1"}' {"ok":true,"_index":"index","_type":"type1","_id":"1","_version":2}
看看修改之后的结果吧
curl -XGET http://localhost:9200/index/type1/1/ {"_index":"index","_type":"type1","_id":"1","_version":2, "_source" : {"time":"2011-1-1","name":"medcl?","blog":"http://log.medcl.net"}}
[翻译]Diving Into ElasticSearch(7)模块配置介绍:cluster
<Date: 2011-09-14> <Category: Diving Into ElasticSearch> 发表评论纯翻译:http://www.elasticsearch.org/guide/reference/modules/cluster.html
貌似国内最近关注elasticsearch的人多了起来。
阅读这篇文章的其余部分 »
Diving Into ElasticSearch (6) 配置文件elasticsearch.yml
<Date: 2011-09-14> <Category: Diving Into ElasticSearch> 发表评论接前面那篇吧[5],ElasticSearch分布式架构要说清楚真不是那么容易,我那就从细节一点点的切入吧。
先看看配置文件吧:elasticsearch.yml
#gateway类型,表示持久化数据存放位置,默认local,推荐的方式,此外还有NFS、HDFS、S3 gateway.type : local #集群名称,区分集群的唯一名称 cluster.name : 'TEST' #索引文件存放目录 #path.data : '/var/elasticsearch/data' #日志文件存放目录 #path.logs : '/var/elasticsearch/logs' #网络配置 #network.tcp.keep_alive : true #network.tcp.send_buffer_size : 8192 #network.tcp.receive_buffer_size : 8192 #gateway.recover_after_nodes : 1 #gateway.recover_after_time : 10s #gateway.expected_nodes : 2 #自动发现相关配置 #discovery.zen.fd.connect_on_network_disconnect : true #discovery.zen.initial_ping_timeout : 10s #discovery.zen.fd.ping_interval : 2s #discovery.zen.fd.ping_retries : 10 #索引snapshot时间只对当gateway设置为NFS时有效 #index.gateway.snapshot_interval : 1s #刷新时间间隔 #index.engine.robin.refresh_interval : -1 #默认索引碎片数 index.number_of_shards : 3 #默认索引副本数 index.number_of_replicas : 1 #默认索引合并因子 #index.merge.policy.merge_factor : 100 #index.merge.policy.min_merge_docs : 1000 #index.merge.policy.use_compound_file : true #indices.memory.index_buffer_size : 5% #Gateway相关配置 # Gateway Settings #gateway: # recover_after_nodes: 1 # recover_after_time: 5m # expected_nodes: 2 #提示:当集群期望节点达不到的时候,集群就会处于block,无法正常索引和查询,说明集群中某个节点未能正常启动,这正是我们期望的效果,block住,避免照成数据的不一致 #强制所有内存锁定,不要没事搞个swap什么的来影响性能 # Force all memory to be locked, forcing JVM to never swap # (make sure to set MIN and MAX mem to the same value) #bootstrap: # mlockall: true #当禁用multcast广播的时候,可以手动设置集群的节点ip # Unicast Discovery (disable multicast) #discovery: # zen: # multicast.enabled: false # unicast.hosts: ["host1", "host2"]
配置文件elasticsearch.yml的可配项比较多,并且修改之后需要重启服务才能生效。



