Return number of maching words in an index

Hi,

I have an index as follow

IDX  text                          cID
#1 - "this is a random text"      - 2
#2 - "another random cool test"   - 3
#3 - "my car is blue       "      - 2
#4 - "lorem ipsum indolor si"     - 3
#5 - "i don't know what is it for"- 2

I have a text to search against :

My very cool text is a long text with many words and random sense.

What i'm trying to achieve is to find how many of exact unique words in the phrase above i have in my whole index with cID = 2

Expected results :
5 (my, text, is, random, a)

Any idea ?

Considering this stackoverflow thread (http://stackoverflow.com/questions/38271068/elasticsearch-return-number-of-maching-words) it seems to be impossible to achieve this with elasticsearch. Someone can confirm ?

You can do it but this requires some client-side logic.

First pass your sentence to the analyze API in order to break it into tokens and deduplicate them.
Then search for each token using a filter on the cID field and terminate_after=1 (for efficiency).
Finally count how many search requests matched.