The most popular (often occurring) tags

Hello

I use documents like this:

{
  "type": "article",
  "docId": "d812aa38f07e",
  "tags": [
    "queries",
    "reply",
    "cartel",
    "story",
    "reviewers"
  ],
  "body": [
    {
      "text": "Many reviewers are so inundated with queries that they only reply to queries for books they want to review. Some will reply. When they do, thank them for their interest. If they would like to receive the send it to them promptly."
    },
    {
      "YTVideo": "-ZQDTXh9DVA"
    },
    {
      "text": "Another reason to have an — you’ll have your hands busy writing the damn book! That’s where your creative process will make or break you. Take it seriously.These quotations are particularly true when it comes to being successful at self-publishing."
    },
    {
      "text": "This is a great post. I am looking forward for the opportunity to participate in this course. I want to become a better writer, and one day, write a book.The only practice today is to  from the Story Cartel Course from the Story Cartel course and read through the first lesson."
    }
  ]
}

Question:
How to make a rating of the most popular (often occurring) tags?

  "tags": [
    "queries",
    "reply",
    "cartel",
    "story",
    "reviewers"
  ]

What new possibilities for solving my question does the new Couchbase 5 have?

Thank you.

If same tag appears multiple times in the same “text” is need to count multiple times.

Not every document has a section “text” and a section “tags”.
Elements in the “tags” section can be repeated in different documents.
I want to get the most popular tags.

For Example: queries in has twice so you need to count as twice is right “text” : “with queries that they only reply to queries”

It would be simpler to assume that all documents look like this:

  "tags": [
    "queries",
    "reply",
    "cartel",
    "story",
    "reviewers"
  ]

In order to evaluate the frequently encountered tag, do I need to use full text search?

    INSERT INTO default VALUES ("a001", { "type": "article", "docId": "d812aa38f07e", "tags": [ "queries", "reply", "cartel", "story", "reviewers" ], "body": [ { "text": "Many reviewers are so inundated with queries that they only reply to queries for books they want to review. Some will reply. When they do, thank them for their interest. If they would like to receive the send it to them promptly." }, { "YTVideo": "-ZQDTXh9DVA" }, { "text": "Another reason to have an — you’ll have your hands busy writing the damn book! That’s where your creative process will make or break you. Take it seriously.These quotations are particularly true when it comes to being successful at self-publishing." }, { "text": "This is a great post. I am looking forward for the opportunity to participate in this course. I want to become a better writer, and one day, write a book.The only practice today is to  from the Story Cartel Course from the Story Cartel course and read through the first lesson." } ] });
   CREATE PRIMARY INDEX ON default;   
    SELECT  tag, SUM(ARRAY_LENGTH(ARRAY v FOR v IN SPLIT(b.text) WHEN v = tag END)) AS cnt
    FROM default AS d
    UNNEST d.tags AS tag
    UNNEST d.body AS b
    WHERE d.type = "article" AND tag IS NOT NULL AND b.text IS NOT NULL
    GROUP BY tag
    ORDER BY cnt DESC;

I’m got a error:
No primary index on keyspace article. Use CREATE PRIMARY INDEX to create one.
What a wrong?

You need to create index based on predicate or you need to create primary index.

It really works, Thanks!