'How should ElasticSearch be configured to index JSON meta data structures in text files?

When adding front matter to a markdown document in i.e. GitLab, I am able to find the property using fulltext search.

---
title: "My subject"
author: "Jane Doe"
tags:
- tag: Book
- tag: Popular
- tag: Romance
---

# Chapter 1 - This is my Markdown

At first, the solution seemed a little bit odd.

If I need to find all Popular documents, I can search for "tag: popular" but not tag:popular. This isn't much of an issue if using YAML in the front matter section, but switching to JSON is a whole other beast.

;;;
{
  "title": "My subject",
  "author": "Jane Doe",
  "tags": [
    {
      "tag": "Book"
    },
    {
      "tag": "Popular"
    },
    {
      "tag": "Romance"
    }
  ]
}
;;;


# Chapter 1 - This is my Markdown

At first, the solution seemed a little bit odd.

Then I'd really like to only search using tag:popular instead of trying to figure out the free text syntax.

Note: Neither GitLab or Azure DevOps can presently render FrontMatter in any other format than YAML. So, to avoid bad rendering, JSON FrontMatter sections needs to be hidden using [comment]:# (hide this).

[JSON]:# (
;;;
{
  "title": "My subject",
  "author": "Jane Doe",
  "tags": [
    {
      "tag": "Book"
    },
    {
      "tag": "Popular"
    },
    {
      "tag": "Romance"
    }
  ]
}
;;;
)

# Chapter 1 - This is my Markdown

At first, the solution seemed a little bit odd.

Actually, the ElasticSearch engine i Azure DevOps do index datastructures found anywhere and make them searchable properties.

However, how should ElasticSearch be configured to support this feature on other vendors such as GitLab?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source