1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
[[mapping-array-type]]
=== Array Type
JSON documents allow to define an array (list) of fields or objects.
Mapping array types could not be simpler since arrays gets automatically
detected and mapping them can be done either with
<<mapping-core-types,Core Types>> or
<<mapping-object-type,Object Type>> mappings.
For example, the following JSON defines several arrays:
[source,js]
--------------------------------------------------
{
"tweet" : {
"message" : "some arrays in this tweet...",
"tags" : ["elasticsearch", "wow"],
"lists" : [
{
"name" : "prog_list",
"description" : "programming list"
},
{
"name" : "cool_list",
"description" : "cool stuff list"
}
]
}
}
--------------------------------------------------
The above JSON has the `tags` property defining a list of a simple
`string` type, and the `lists` property is an `object` type array. Here
is a sample explicit mapping:
[source,js]
--------------------------------------------------
{
"tweet" : {
"properties" : {
"message" : {"type" : "string"},
"tags" : {"type" : "string", "index_name" : "tag"},
"lists" : {
"properties" : {
"name" : {"type" : "string"},
"description" : {"type" : "string"}
}
}
}
}
}
--------------------------------------------------
The fact that array types are automatically supported can be shown by
the fact that the following JSON document is perfectly fine:
[source,js]
--------------------------------------------------
{
"tweet" : {
"message" : "some arrays in this tweet...",
"tags" : "elasticsearch",
"lists" : {
"name" : "prog_list",
"description" : "programming list"
}
}
}
--------------------------------------------------
Note also, that thanks to the fact that we used the `index_name` to use
the non plural form (`tag` instead of `tags`), we can actually refer to
the field using the `index_name` as well. For example, we can execute a
query using `tweet.tags:wow` or `tweet.tag:wow`. We could, of course,
name the field as `tag` and skip the `index_name` all together).
|