Search Email Address


We are using elasticsearch with rails.

We have users that are indexed by email and name.

When the query string includes email address, the results include all the users with the same email domain.
For example, when searching: "", the search results are the users with these email addresses: "", "", "".

Our expected search result is: "".

We've tried to send the query string with quotes and got: "", "".

In addition, when searching "dave" we would like to get both "" and "" and when searching "dave@ex" only "".

This is the relevant elasticsearch code:

def as_indexed_json(options={})
    { :name =>,
      :email => }

def, user_id, organization_id)
          query: {
                  { must: 
                    { query_string: {
                      query: query,
                      fields: [ :name, :email ],
                      analyzer: 'standard'
          size: 10000

settings  analysis: {
                filter: {
                    ngram_filter: {
                        type: "nGram",
                        min_gram: 2,
                        max_gram: 20
                analyzer: {
                    ngram_analyzer: {
                        tokenizer: "standard",
                        type: "custom",
                        filter: ["lowercase", "ngram_filter"]
            } do
    mapping do
      indexes :name, analyzer: :ngram_analyzer
      indexes :email, analyzer: :ngram_analyzer

Please let me know how to get these search results.

Thank you,

To search for the exact email address among other text strings, you need to create a custom analyzer using the tokenizer below