记录生活
标签 Tag : elasticsearch

ElasticSearch里DSL使用事故一则:_cache参数

<Category: Diving Into ElasticSearch> 发表评论

大家在写QueryDSL的时候,要特别注意参数,比如今天我就碰到了一个关于_cache的问题 由于使用自己写的QueryBuilder来生成QueryDSL查询语句,所以有些参数虽然没有指定,但是默认带上了,但有些情况下不注意就会出现问题。 如下例: 阅读这篇文章的其余部分 »

本文来自: ElasticSearch里DSL使用事故一则:_cache参数

doc.elasticsearch.cn解析成功了

<Category: Diving Into ElasticSearch> 发表评论

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

...

文档比较多,招志愿者一起翻译。

本文来自: doc.elasticsearch.cn解析成功了

jekyll&es-doc部署脚本

<Category: Linux, VPS维护日志> 发表评论

https://github.com/mojombo/jekyll/wiki/Deployment

jekyll&-doc部署脚本
阅读这篇文章的其余部分 »

本文来自: jekyll&es-doc部署脚本

基于私有云的elasticsearch批量部署

<Category: Diving Into ElasticSearch, 搜索> 发表评论

基于私有云的elasticsearch批量部署
阅读这篇文章的其余部分 »

本文来自: 基于私有云的elasticsearch批量部署

elasticsearch里的search_type

<Category: Diving Into 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//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;
 
    }

本文来自: elasticsearch里的search_type

elasticsearch技术交流群,欢迎加入

<Category: 小道消息> 发表评论

新建了2个qq群,欢迎大家一起交流elasticsearch方面的相关内容。
群1:190605846
群2:暂不开放
另外,已经刚申请了elasticsearch.cn域名,打算组建一个elasticsearch在国内的交流社区,整理收集相关的资料文档,方便新手学习elasticsearch和促进elasticsearch在国内的推广。

第一步,打算先将官方的站点的文档翻译下,毕竟目前还没有比那更完善的文档了,由于文档比较多,所以在这里希望能招募有共同想法的童鞋一起来完成这项伟大的工作。

有什么想法请留意或加QQ群吧。
you know for search , :)

本文来自: elasticsearch技术交流群,欢迎加入

Diving Into ElasticSearch(10)精确控制之Routing使用

<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..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(10)精确控制之Routing使用

Diving Into ElasticSearch(9)Parent-Child特性使用

<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(9)Parent-Child特性使用

Diving Into ElasticSearch(8)Mapping&Schema

<Category: Diving Into ElasticSearch> 4 条评论

前面应该介绍过ES是Schema Free,但是Schema Free不是说没有Schema,和Solr一样,ElasticSearch也可以设置document的schema,ES里的名字叫Mapping,其实无非就是设置document包含哪些Field,然后对每一个Field个性化的设置索引类型,是否存储,以及设置索引分析器和查询使用的分析器,Es和Solr相比有一个我认为最好的特性:就是支持Object类型,你可以像操作对象一样对对象的某个属性进行索引和查询,简单演示如下:
阅读这篇文章的其余部分 »

本文来自: Diving Into ElasticSearch(8)Mapping&Schema

[翻译]Diving Into ElasticSearch(7)模块配置介绍:cluster

<Category: Diving Into ElasticSearch> 发表评论

纯翻译:http://www..org/guide/reference/modules/cluster.html
貌似国内最近关注elasticsearch的人多了起来。
阅读这篇文章的其余部分 »

本文来自: [翻译]Diving Into ElasticSearch(7)模块配置介绍:cluster