设为首页 加入收藏

TOP

Elasticsearch搜索调优权威指南 (1/3)(一)
2019-09-17 17:30:08 】 浏览:53
Tags:Elasticsearch 搜索 权威 指南 1/3

本文首发于 vivo互联网技术 微信公众号 https://mp.weixin.qq.com/s/qwkZKLb_ghmlwrqMkqlb7Q
英文原文:https://qbox.io/blog/elasticsearch-search-tuning-5-0-ultimate-guide
作者:Adam Vanderbush
译者:杨振涛

目录

  1. 文档建模
  2. 全局序列号和延迟
  3. 多代关系
  4. 为文件系统缓存分配内存

Elasticsearch搜索调优权威指南,是QBOX在其博客上发布的系列文章之一,本文是该系列的第一篇,主要从文档建模、内存分配、文件系统缓存、GC和硬件等方面介绍了优化查询性能的一些经验。

Elasticsearch 5.0.0确实是在2.x之后的一个大版本,为大家带来了许多新东西。Elasticsearch现在作为Elastic Stack中的一员,与整个技术栈的其他产品的版本号已经对齐,现在Kibana、Logstash、Beats和Elasticsearch全都是5.0版本了。

这个版本的Elasticsearch是目前为止最快、最安全、最弹性,也是最易用的,而且还带来了很多的改进和新特性。

我们已经通过“Elasticsearch性能调优权威指南”系列,介绍了一些性能调优的基本经验和方法,解释了每一步最关键的系统设置和衡量指标。该系列共分下列3个部分:

  • The Authoritative Guide to Elasticsearch Performance Tuning (Part 1) 
  • The Authoritative Guide to Elasticsearch Performance Tuning (Part 2) 
  • The Authoritative Guide to Elasticsearch Performance Tuning (Part 3)

索引决策也很重要,它对如何搜索数据有很大的影响。如果是一个字符串字段,是否需要分词或归一化?如果是,怎么做?如果是一个数值型属性,需要哪种精度?还有很多其他类型,比如date-time、geospatial shape以及父子关系等,需要更多特别的考虑。

我们也通过一个系列教程讨论了“Elasticsearch索引性能优化”,介绍了一些通用的技巧和方法,来最大化索引的吞吐量并降低监控和管理的负载。该教程分如下3个部分:

本文旨在推荐一些搜索调优技术、策略以及Elasticsearch 5.0及以上的推荐特性。

 

1.文档建模

内部对象属性数组并不像期望的那样工作。Lucene 中没有内部对象的概念,所以Elasticsearch把对象层次展开到一个由属性名称和属性值组成的简单列表中。以下列文档为例:

curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d '{
 "group" : "fans",
 "user" : [
   {
     "first" : "John",
     "last" :  "Smith"
   },
   {
     "first" : "Alice",
     "last" :  "White"
   }
 ]
}'

该请求会在内部转换为如下的文档形式:

{
  "group" :        "fans",
  "user.first" : [ "alice", "john" ],
  "user.last" :  [ "smith", "white" ]
}

如果需要索引对象数组,并维护数组中每个对象的依赖关系,应当使用内嵌数据类型而不是对象数据类型。内嵌对象在内部会把数组中的每个对象当作单独的隐藏文档来索引,即使用下述内嵌查询,可以单独查询每个内嵌对象:

curl -XPUT 'ES_HOST:ES_PORT/my_index?pretty' -H 'Content-Type: application/json' -d '{
 "mappings": {
   "my_type": {
     "properties": {
       "user": {
         "type": "nested"
       }
     }
   }
 }
}'

curl -XPUT 'ES_HOST:ES_PORT/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d '{
 "group" : "fans",
 "user" : [
   {
     "first" : "John",
     "last" :  "Smith"
   },
   {
     "first" : "Alice",
     "last" :  "White"
   }
 ]
}'


curl -XGET 'ES_HOST:ES_PORT/my_index/_search?pretty' -H 'Content-Type: application/json' -d '{
 "query": {
   "nested": {
     "path": "user",
     "query": {
       "bool": {
         "must": [
           { "match": { "user.first": "Alice" }},
           { "match": { "user.last":  "Smith" }}
         ]
       }
     }
   }
 }
}'

curl -XGET 'ES_HOST:ES_PORT/my_index/_search?pretty' -H 'Content-Type: application/json' -d '{
 "query": {
   "nested": {
     "path&
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇sql server单个字段列转行由".. 下一篇2.6 数据库更新特定字段SQL/语句块

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目