Count number of keyword occurrences with query_string

Hello and good day ElasticSearch Team and Developers!

This is in relation with my StackOverflow post: https://stackoverflow.com/questions/56932330/elasticsearch-count-number-of-keyword-occurences-in-a-document

I'm searching through my index named web with a query_string query as:

[
    "query_string" => [
        "default_field" => $content,
        "query" => $keywords
    ]
]

Where as the $keywords variable contains:

("MCU" OR "Marvel" OR "Spiderman")

Meaning, I'm looking for documents throughout my Index that has those $keywords mentioned.

I'm satisfied with the fetched/retrieved documents, however, my dilemma is that I need to COUNT THE NUMBER OF OCCURRENCE those $keywords appeared per document.

Let's say I have a document with an ID of #17. I want to determine how many times either MCU or Marvel or Spiderman appeared in that document's content field

Any chances for this to work on Elasticsearch?

I'm using:
Elasticsearch: v7.2
Application: Laravel v5.7

Thank you very much!

Would that help?

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