How to flatten json for elasticsearch document indexing
- Step 1Paste a representative document — Paste a single JSON document or a NDJSON sample. For Elasticsearch, use a representative document that includes all fields your mapping should cover — fields absent from a sample document will not appear in the flattened output.
- Step 2Choose dot notation for Elasticsearch — Select '.' as the key separator. Elasticsearch uses dot notation in its query DSL and mapping definitions, so user.profile.age in the flat JSON matches the nested mapping path directly.
- Step 3Review array handling — JSON arrays of primitives (strings, numbers) become multi-value flat fields — Elasticsearch stores them as arrays natively. Arrays of objects should be handled with Elasticsearch's nested mapping type rather than flattened.
- Step 4Use the flat document to design the index mapping — Copy the flattened document and use the flat keys to define your Elasticsearch index mapping's properties object. Each flattened key becomes a property with an inferred type (keyword, text, integer, float, date).
Frequently asked questions
Should I flatten arrays of objects for Elasticsearch?+
No. Arrays of objects (e.g. an order with multiple line items) should be indexed using Elasticsearch's nested field type, which preserves the relationship between fields within each array element. Flattening arrays of objects loses the relationship and causes incorrect cross-object query matches. Only flatten arrays of primitive values.
How do I use the flattened keys to generate an Elasticsearch index mapping?+
After flattening, use the JSON Schema Generator tool on the flattened document to infer a JSON Schema. The property types in the schema (string, number, boolean) map to Elasticsearch types: string →’ keyword or text, number →’ integer or float, boolean →’ boolean. Review and adjust keyword vs text based on whether you need full-text search on the field.
Is the document content — including any log data — sent to JAD Apps?+
No. Flattening runs entirely in your browser. Log payloads, API response bodies, and any PII in the JSON documents are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.