How to display json keys in Search UI query response

I have json docs that contain one field "content" (and ID) with many nested json key:value objects. In addition, there can be many of the same keys int the document.

An example would look something like this:

{
"content": [
{"url": "https://www.xxx.com"
{"title": "doc title"},
{"person": "person1"},
{"city": "city1"
{"person": "person2"},
{"person": "person3"}
]}

I can index and search the documents. However, I want to display the URL, Title, etc., as the query response. I see how to do this if they are fields in a simpler structure, but unclear how to display these based on the example. Currently, I get the "content" with the key:value pair based on the search term.
i.e.
"content": {"title":"doc title"}
"id": "doc-12233444"
or
"content": {"url":"https://www.xxx.com"}
"id": "doc-12233444"

This is how the field in the above example is used in Kibana:
{"field": "content.title.keyword"}

I'm a nube at Elastic App Search. Any help would be greatly appreciated.

Thanks in advance!

Hey @cerro. Your best bet, if possible, is to index your documents as a flat structure. App Search unfortunately doesn't have first class support for nested fields like that.

That being said, if you index the content from your example, you'll get an API response that contains the following:

[
  {
    "content": {
      "raw": [
        "{\"url\":\"https://www.xxx.com\"}",
        "{\"title\":\"doc title\"}",
        "{\"person\":\"person1\"}",
        "{\"city\":\"city1\"}",
        "{\"person\":\"person2\"}",
        "{\"person\":\"person3\"}"
      ],
      "snippet": "{&quot;<em>person</em>&quot;:&quot;<em>person1</em>&quot;}"
    },
    "id": {
      "raw": "1",
      "snippet": null
    },
    "_meta": {
      "score": 1.5658082
    }
  }
]

The "snippet" value, which can be used for highlighting, will only contain a single value based on the search term, as you mentioned. However, the "raw" field can be used to display all values from content.

Does that help?

Thanks! I'll give that try.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.