AI Hints
Home›Elasticsearch Tutorial›Field Types in Depth
Elasticsearch · Lesson 45 of 120

Objects and Arrays

JSON inside JSON.

⏱ 2 min read▶ Video at 41:32🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Documents can hold objects inside them, like a supplier with a name and a country. And any field can hold a list of values, like several tags.

  • Objects inside
  • Lists of values
  • No special type

An object and a list

Supplier is an object, with name and country inside. Tags is just a list, and needs no special type. We search with dot notation, supplier dot country. Run it. The product is found by its supplier's country, and by one of its tags.

Dev Tools Consoletext
PUT products/_doc/1?refresh=true&filter_path=result
{ "name": "Storm Rain Jacket",
  "supplier": { "name": "Peak Mills", "country": "Portugal" },
  "tags": ["rain", "hiking"] }

GET products/_count?filter_path=count
{ "query": { "bool": { "filter": [
  { "match": { "supplier.country": "portugal" } },
  { "match": { "tags": "hiking" } } ] } } }
Output
# PUT products/_doc/1 201 Created
{"result": "created"}

# GET products/_count 200 OK
{"count": 1}

How they are stored

Inside, objects are flattened into dotted field names, like supplier dot name. A list field just has several values. A document matches if any value in the list matches. There's no array type to declare.

keyvalue
Objectsflattened: supplier.name
Arraysmany values, same type
Matchany value matches
Declareno array type

Summary

Objects are flattened into dotted fields, and any field can hold a list. Next, a problem with lists of objects, and the nested type.

Key takeaways
  • Objects
  • Dot notation
  • Arrays
Next up: The nested Type — lists of objects