Elasticsearch方案优化 [英] Elasticsearch scheme optimization

查看:86
本文介绍了Elasticsearch方案优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用ElasticSearch时,我可以将json文档保存到其中,并默认情况下按它们搜索.另外,我可以指定一些索引设置,在其中可以描述字段类型和索引设置.我的问题是关于在ElasticSearch中存储数据的内部实现.像在MongoDB中一样,我可以在此处存储动态json数据,因此所有文档都将按原样保存(实际上是在BSON中,但此处未列出).例如:

When I am using ElasticSearch I can save json documents into it and search by them by default. Also I can specify some index settings where I can describe fields type and settings for indexing. My question is about internal implementation of storing data in ElasticSearch. Like in MongoDB I can store dynamic json data here, so all documents will saved as is (actually in BSON but it doesn't metter here). For example:

{
  firstName:"A",
  lastName: "B"
}

在这里我们可以看到方案数据"比实际数据"占用更多的磁盘空间.因此,在MongoDB中,最好将方案数据"的大小最小化,如下所示:

Here we can see that "scheme data" take more disk space than "actual data". So in MongoDB it is good practice to minimize size of "scheme data", like this:

{
   f:"A",
   l:"B"
}

,并在应用程序代码中提供一些映射以支持此方案. 在Elasticsearch(Lucene)中,我可以指定一些方案,因此在内部它只能保存实际数据"而不是"actual + scheme",但是我对此不确定,因为我还可以存储动态json数据.

and provide some mapping in application code to support this scheme. In Elasticsearch (Lucene) I can specify some scheme, so internally it can save only "actual data" not "actual+scheme", but I am not sure about this, because I can store dynamic json data also.

所以问题是我应该在ElasticSearch中实现这种优化吗?

So question is should I implement such optimization in ElasticSearch ?

推荐答案

是的,它会占用更多的空间,但是我不会担心. Elasticsearch中的文档存储为_source字段中的完整JSON.它会占用磁盘空间,并在返回结果时临时使用内存.

Yes, it will take slightly more space, but I wouldn't worry about. A document in Elasticsearch is stored as the full JSON, in the _source field. It takes up disk space, and uses memory temporarily when returning results.

但是,您可以设置要压缩的_source字段,并且从0.90版本开始的Elasticsearch版本中,整个段都被压缩了,并且字段名称是压缩的不错选择.

But, you can set the _source field to be compressed, and in version of Elasticsearch from 0.90 onwards, the whole segment is compressed, and field names are good candidates for compression.

我希望保持文档可读性而不是含糊不清.

I'd prefer to keep my documents readable rather than cryptic.

这篇关于Elasticsearch方案优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆