# How can I retrieve the information about where the highlight was found?

**URL:** <https://discuss.elastic.co/t/how-can-i-retrieve-the-information-about-where-the-highlight-was-found/369827>\
**Category:** Elastic Search\
**Created:** [October 30, 2024, 2:44pm UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-information-about-where-the-highlight-was-found/369827 "2024-10-30T14:44:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Talles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/talles/32/138863_2.png) [@Talles](https://discuss.elastic.co/u/Talles)\
**Post date:** [October 30, 2024, 2:44pm UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-information-about-where-the-highlight-was-found/369827/1 "2024-10-30T14:44:32Z")

</div>

Hi everyone,

I have a field named 'name\_of\_company' and `anexos` (type List), which contains three fields: `name`, `url`, and `pages`. Within the `pages` (type List) field, I have two additional fields: `num_page` and `text`.

I am searching for information in `anexos > pages > text`, which works fine. However, in the highlight section, I would like to know the `num_page`, `name`, and `url` (of the `anexo`) associated with each highlight that is found.

In the highlight I can see 'name\_of\_company' but I can't see the name and  
url of the "anexos" .

**this is my map**

```auto
"pagina_h": {
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "anexos": {
          "properties": {
            "link": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "paginas": {
              "properties": {
                "num_pagina": {
                  "type": "long"
                },
                "texto": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            },
            "titulo": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "url": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        },
        "ano": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

```

**here is my console**

```auto
GET page_h/_search
{
  "query": {
    "match": {
      "anexos.paginas.texto": "key_word"
    }
  },
  "highlight": {
    "fields": {
      "anexos.paginas.texto": {
        "fragment_size": 500
      }
    }
  }
}

```

**and here is my result**

```auto
   {
    "took": 260,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 12,
            "relation": "eq"
        },
        "max_score": 4.536918,
        "hits": [
            {
                "_index": "pagina_h",
                "_id": "1",
                "_score": 4.536918,
                "_ignored": [
                    "anexos.paginas.texto.keyword"
                ],

                "highlight": {
                    "anexos.paginas.texto": [
                        """ example """
                    ]
                }
            },
            {
                "_index": "pagina_h",
                "_id": "760",
                "_score": 1.6609094,
                "_ignored": [
                    "anexos.paginas.texto.keyword"
                ],
                "highlight": {
                    "anexos.paginas.texto": [
                        """ example """
                    ]
                }
            },
            {
                "_index": "pagina_h",
                "_id": "761",
                "_score": 1.6334696,
                "_ignored": [
                    "anexos.paginas.texto.keyword"
                ],
                "highlight": {
                    "anexos.paginas.texto": [
                        """ example """
                    ]
                }
            },
            {
                "_index": "pagina_h",
                "_id": "764",
                "_score": 1.3660059,
                "_ignored": [
                    "anexos.paginas.texto.keyword"
                ],     

```

Another example that I put in json, note that I got the highlight from '

> anexos\> paginas \> text'

and note that I can even identify that the highlight came from the source with

> "type" : "unsercover",  
> "num": "756",  
> etc.  
> etc.

**However** In highight I can't identify the ' 'title' and 'url' (in anexos ) that it came from.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/d/6d479a24689d677e8ee8ff498019019f791ddacc.png)

**What I would like to see**

The 'title', 'url' (from anexos) and 'num\_page' where the highlight was done.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 2, 2024, 12:28am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-information-about-where-the-highlight-was-found/369827/2 "2024-11-02T00:28:47Z")

</div>

Welcome @Talles .

If I understand correctly, you want to have the highlight in addition to the "attachments.pages.text" field, also in the "attachments.pages.title" and "attachments.pages.url" fields.

If that's the case, the query could be like this:

```auto
{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [
        {
          "match": {
            "anexos.paginas.texto": "Title page document1"
          }
        },
        {
          "match": {
            "anexos.titulo": "Title page document1"
          }
        },
        {
          "match": {
            "anexos.url": "Title page document1"
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "anexos.paginas.texto": {
      },
      "anexos.titulo": {
      },
      "anexos.url": {
      }
    }
  }
}

```

Output:

```auto
"hits": [
      {
        "_index": "livros",
        "_id": "rQA36pIB3NhMlEBWmyNR",
        "_score": 0.970927,
        "_source": {
          .....
        "highlight": {
          "anexos.url": [
            "https://example.com/<em>document1</em>"
          ],
          "anexos.titulo": [
            "Document 1 <em>Title</em>"
          ],
          "anexos.paginas.texto": [
            "This is the first <em>page</em> of the document.",
            "This is the second <em>page</em> of the document."
          ]
        }
      }
    ]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 30, 2024, 12:29am UTC](https://discuss.elastic.co/t/how-can-i-retrieve-the-information-about-where-the-highlight-was-found/369827/3 "2024-11-30T00:29:46Z")

</div>

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