- ElasticSearch Cookbook
- Alberto Paro
- 301字
- 2021-04-02 10:10:00
Mapping arrays
Arrays or multi-value fields are very common in data models, but not natively supported in traditional SQL solutions.
In SQL, multi-value fields require the creation of accessory tables that must be joined to gather all the values, resulting in poor performance when the cardinality of records is huge.
Getting ready
You need a working ElasticSearch cluster.
How to do it...
Every field is automatically managed as an array. For example, to store tags for a document, the mapping will be as shown in the following code snippet:
{ "document" : { "properties" : { "name" : {"type" : "string", "index":"analyzed"}, "tag" : {"type" : "string", "store" : "yes" , "index":"not_analyzed"}, } } }
This mapping is valid for indexing the following documents:
{"name": "document1", "tag": "awesome"}
and
{"name": "document2", "tag": ["cool", "awesome", "amazing"] }
How it works...
ElasticSearch transparently manages the array; there is no difference if you declare a single value or a multi-value due to its Lucene core nature.
Multiple values for fields are managed in Lucene, adding them to a document with the same field name (index_name in ElasticSearch). If the index_name
field is not defined in the mapping, it is taken from the name of the fields. It can also be set to other values for custom behaviors, such as renaming a field at indexing level or merging two or more JSON fields in a single Lucene field. Redefining the index_name
field must be done with caution as it also affects the search.
For people coming from SQL, this behavior may seem quite strange, but this is a key point in the NoSQL world as it reduces the need for joint query and creating different tables to manage multiple values.
- Linux實戰(zhàn)
- Learning Android Intents
- 嵌入式Linux系統(tǒng)開發(fā):基于Yocto Project
- Kubernetes網(wǎng)絡(luò)權(quán)威指南:基礎(chǔ)、原理與實踐
- 嵌入式操作系統(tǒng)(Linux篇)(微課版)
- 深入理解eBPF與可觀測性
- 嵌入式Linux應(yīng)用開發(fā)菜鳥進(jìn)階
- Ceph分布式存儲實戰(zhàn)
- Kali Linux 2018:Windows Penetration Testing
- 計算機(jī)系統(tǒng):基于x86+Linux平臺
- 分布式高可用架構(gòu)之道
- Windows Vista終極技巧金典
- Mastering Windows 8 C++ App Development
- 鴻蒙HarmonyOS應(yīng)用開發(fā)從入門到精通
- Linux指令從初學(xué)到精通