- ElasticSearch Cookbook
- Alberto Paro
- 446字
- 2021-04-02 10:10:00
Mapping an object
The object is the base structure (also called as record in SQL). ElasticSearch extends the traditional use of object, allowing recursive embedded objects.
Getting ready
You will require a working ElasticSearch cluster.
How to do it...
We can rewrite the order mapping of the Mapping base types recipe using an array of items as shown in the following code:
{ "order" : { "properties" : { "id" : {"type" : "string", "store" : "yes", "index":"not_analyzed"}, "date" : {"type" : "date", "store" : "no", "index":"not_analyzed"}, "customer_id" : {"type" : "string", "store" : "yes", "index":"not_analyzed"}, "sent" : {"type" : "boolean", "store" : "no", "index":"not_analyzed"}, "item" : { "type" : "object", "properties" : { "name" : {"type" : "string", "store" : "no", "index":"analyzed"}, "quantity" : {"type" : "integer", "store" : "no", "index":"not_analyzed"}, "vat" : {"type" : "double", "store" : "no", "index":"not_analyzed"} } } } } }
How it works...
ElasticSearch speaks native JSON. So, every complex JSON structure can be mapped into it.
When ElasticSearch is parsing an object type, it tries to extract fields and processes them as its defined mapping; otherwise, it learns the structure of the object using reflection.
The most important properties for an object are as follows:
properties
: This is a collection of fields or objects (we can consider them as columns in the SQL world).enabled
(defaults totrue
if the object should be processed): If this is set tofalse
, the data contained in the object is not indexed and it cannot be searched.dynamic
(defaults totrue
): This property allows ElasticSearch to add new field names to the object using reflection on values of inserted data. If it's set tofalse
, when you try to index an object contained in a new field type, it'll be rejected silently. If it's set tostrict
, when a new field type is present in the object an error is raised skipping the index process. Control dynamic parameters allows being safe about change in the document structure.include_in_all
(defaults totrue
): This property adds the object values to the special_all
field (used to aggregate the text of all document fields).
The most used property is properties
that allows mapping the fields of the object in ElasticSearch fields.
Disabling the indexing part of a document reduces the index size and allows storing data that must not be searched.
There's more...
Also, there are properties that are rarely used, such as index_name
and path
, which changes the how
Lucene index the object, modifying the inner structure of an index.
See also
- There are special objects that are described in the Mapping a document, Managing a child document, and Mapping a nested document recipes.
- 電腦組裝與系統(tǒng)安裝
- 全屋互聯(lián):智能家居系統(tǒng)開發(fā)指南
- Containerization with LXC
- 發(fā)布!設(shè)計(jì)與部署穩(wěn)定的分布式系統(tǒng)(第2版)
- 網(wǎng)絡(luò)操作系統(tǒng):Windows Server 2003管理與應(yīng)用
- Arch Linux Environment Setup How-to
- Persistence in PHP with the Doctrine ORM
- Ganglia系統(tǒng)監(jiān)控
- 深入理解eBPF與可觀測(cè)性
- Windows Server 2019 Administration Fundamentals
- 操作系統(tǒng)分析
- 鴻蒙HarmonyOS手機(jī)應(yīng)用開發(fā)實(shí)戰(zhàn)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程(Windows 7+MS Office 2010)
- Java EE 7 Developer Handbook
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)