`
donlianli
  • 浏览: 335966 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Group-logo
Elasticsearch...
浏览量:216414
社区版块
存档分类
最新评论

Elasticsearch升级至1.x后API的变化-三

阅读更多
 
请支持原创:http://donlianli.iteye.com/blog/2091127
 
1、索引格式

1.x之前的版本,被索引的文档type会同时出现在url和传输的数据格式中,如下:

 

PUT /my_index/my_type/1
{
  "my_type": {
     ... doc fields ...
  }
}

 

这种方式不太妥,如果一个document,本身也有my_type域,那么就会有歧义。1.x版本如果碰到上面的命令,会把my_type当成一个document的域进行处理。如果还想像以前一样使用,可以设置参数index.mapping.allow_type_wrapper.

2、搜索
新的搜索接口,要求参数中必须有一个顶级参数query。count,delete-by-query和validate-query这三个命令,认为query这个json对象全是查询条件。新的格式如下:
GET /_count
{
   
"query":{
       
"match":{
           
"title":"Interesting stuff"
       
}
   
}
}

1.x之前,query下面还可以包含filter。下面是0.90版的查询:

GET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy'-d '{
   
"query":{
       
"filtered":{
           
"query":{
               
"query_string":{
                   
"query":"some query string here"
               
}
           
},
           
"filter":{
               
"term":{"user":"kimchy"}
           
}
       
}
   
}
}
'//这种格式不再支持

3、多字段搜索(Multi-fields)
新的格式如下:
"title":{
   
"type":"string",
   
"fields":{
       
"raw":   {"type":"string","index":"not_analyzed"}
   
}
}
4、停止词

新的版本没有使用英语默认的停止词(默认没有停止词)。

5、不带年份的日期值

新的版本,当没有指定是哪一年时,默认认为是1970年(在索引和搜索时都这样对待)。


6、参数
  • meters作为地理搜索的默认单位(1.x之前是miles)
  • min_similarity,fuzziness和edit_distance这些参数都别统一修改成了fuzziness。
  • ignore_missing参数被expand_wildcard,ignore_unavailable和allow_no_indices替代。
  • 在删除操作中,必须指定一个索引名称或者匹配符。
# v0.90 - delete all indices:
DELETE
/

# v1.0 - delete all indices:
DELETE
/_all
DELETE
/*
7、返回值
  • 返回值中ok字符已经被移除,作者认为这个附加信息毫无意义
  • found,not_found和exists参数被统一成为“found"。

Field values, in response to the fields parameter, are now always returned as arrays. A field could have single or multiple values, which meant that sometimes they were returned as scalars and sometimes as arrays. By always returning arrays, this simplifies user code. The only exception to this rule is when fields is used to retrieve metadata like the routing value, which are always singular. Metadata fields are always returned as scalars.

The fields parameter is intended to be used for retrieving stored fields, rather than for fields extracted from the _source. That means that it can no longer be used to return whole objects and it no longer accepts the _source.fieldname format. For these you should use the _source _source_include and _source_exclude parameters instead.

 

  • 参数查询中,返回的结果也是JSON格式。
  • analyze相关的API,不再支持直接返回文本格式的结果,只支持JSON和YAML格式。
8、不支持的操作

 

 

  • 文本搜索(text query)已经被移除,请使用匹配查询(match query)
  • 面向域的搜索(field query)已经被移除,请使用query_string代替
  • 面向文档的加权_boost字段已经移除,请使用function_score代替
  • path参数被移除,请使用copy_to参数
  • custom_score和custom_boost_score不再被支持,请使用fuction_score代替

 

关于我,邯郸人。
对这类话题感兴趣?欢迎发送邮件至donlianli@126.com
请支持原创:http://www.iteye.com/blogs/subjects/elasticsearch-tutor
 
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics