Is it possible to count tokens which matched documents?

Hello,

I want to find which term matched on documents that results of query. I tried to using "highlight" but it does responsed with poor results.(I need more digging time to with them)

I want to know alternative way to find which term matched on document result.

Below example my codes, After request , I expect that getting ["Protein-A","Protein-C"] or ["Protein-A"] or ["Protein-C"] matched from document result.

GET papers/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "terms": {
            "title": [
              "Genetic",
              "Phenotype",
              "Crispher"
            ]

          }
        },
        {
          "terms": {
            "main_content": [
              "Protien-A",
              "Protein-B",
              "Protien-C"
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "type": "unified",
    "fields": {
      "main_content": {
        "boundary_scanner": "word",
        "fragment_size": 20,
        "number_of_fragments": 10,
        "pre_tags": [
          "<em>"
        ],
        "post_tags": [
          "</em>"
        ]
      }
    }
  }
}

Do you want to count the matches in all documents or just be more specific about where they matched in the top hits returned?

I want which term exactly matched on each result documents.

I mean that If search multiple term list("terms query") in document, generally elasticsearch result document didn't include which terms matched on documents.

Specifically, I looking for more result about document which term exactly matched.(Not count information, each document have matched specific term list a must.)

This discussion may be relevant then.

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