Elasticsearch : search results on clicking on Hashtag
<p>I have a hashtag with tags in camel Case like #teamIndia. Now when this hashtag is clicked, it should fetch all results which have "#teamIndia" in it, It should first show results with "#teamIndia", then results with "teamIndia" and then "team India" and then "team" or "India" and so on.</p>

<p>What I am doing: </p>

<p>Search text:
<strong>"#teamIndia", "#NEWYORK", "#profession", "#2016"</strong></p>

<pre><code>POST /clip
{
    "settings": {
        "analysis": {
            "char_filter" : {
                "space_hashtags" : {
                    "type" : "mapping",
                    "mappings" : ["#=&gt;|#"]
                }
            },
            "filter": {
                "substring": {
                    "max_gram": "20",
                    "type": "nGram",
                    "min_gram": "1",
                    "token_chars": [
                        "whitespace"
                    ]
                },
                "camelcase": {
                    "type": "word_delimiter",
                    "type_table": ["# =&gt; ALPHANUM", "@ =&gt; ALPHANUM"]
                },
                "stopword": {
                    "type":       "stop",
                    "stopwords": ["and", "is", "the"]
                }
            },
            "analyzer": {
                "substring_analyzer": {
                    "filter": [
                        "lowercase",
                        "substring"
                    ],
                    "tokenizer": "standard"
                },
                "camelcase_analyzer": {
                    "type" : "custom",
                    "char_filter" : "space_hashtags",
                    "tokenizer" : "whitespace",
                    "filter": [
                        "camelcase",
                        "lowercase",
                        "stopword"
                    ]
                }
            }
        }
    },
    "mappings": {
        "Clip": {
            "properties": {
                "description": {
                    "type": "multi_field",
                    "fields": {
                        "description": {
                            "type": "string",
                            "analyzer": "substring_analyzer",
                            "search_analyzer": "standard"
                        },
                        "raw": {
                            "type": "string",
                            "index": "not_analyzed"
                        },
                        "hashtag": {
                            "type": "string",
                            "index": "analyzed",
                            "analyzer": "camelcase_analyzer"
                        }
                    }
                },
                ....
            }
        }
    }
}
</code></pre>

<p>Docs example :-</p>

<pre><code>POST /clip/Clip/2 {"id" : 1, "description" : "TheBestAndTheBeast"}

POST /clip/Clip/3 {"id" : 2, "description" : "bikes in DUBAI TheBestAndTheBeast profession"}

POST /clip/Clip/3 {"id" : 2, "description" : "Know how a software engineer surprised his wife!    &amp;lt;a href=&amp;quot;search/clips?q=%23theProvider&amp;amp;source=hashtag&amp;quot; ng-click=&amp;quot;handleModalClick()&amp;quot;&amp;gt; #theProvider &amp;lt;/a&amp;gt;     rioOlympic   &amp;lt;a href=&amp;quot;search/clips?q=%23DUBAI&amp;amp;source=hashtag&amp;quot; ng-click=&amp;quot;handleModalClick()&amp;quot;&amp;gt; #DUBAI &amp;lt;/a&amp;gt;    &amp;lt;a href=&amp;quot;search/clips?q=%23TheBestAndTheBeast&amp;amp;source=hashtag&amp;quot; ng-click=&amp;quot;handleModalClick()&amp;quot;&amp;gt; #TheBestAndTheBeast &amp;lt;/a&amp;gt;   &amp;lt;a href=&amp;quot;search/clips?q=%23rioOlympic&amp;amp;source=hashtag&amp;quot; ng-click=&amp;quot;handleModalClick()&amp;quot;&amp;gt; #rioOlympic &amp;lt;/a&amp;gt;"}
</code></pre>

<p>** Search Query **</p>

<pre><code>GET clip/_search
{
"size": 100,
"query": {
    "filtered": {
        "query": {
            "bool": {
                "must":
                   {
                    "query_string": {
                        "fields": [
                           "description.hashtag"
                        ],
                        "query": "teamIndia"
                    }                         
                },
                "should": { 
                    "match": 
                        { "description.raw": "#teamIndia"}   
                }
            }
        }
    }
}
</code></pre>

<p>}</p>

<p><strong>Excepted Result:</strong>
"#teamIndia",
"teamIndia",
"team India",
"team",
"India",</p>

<p>and similar for other test keywords. </p>