NEST request for exact text matching

I am trying to write a NEST request that should return results based on exact string matching. I have researched online and there are suggestions for using Term, Match, MatchPhrase. I tried all this, but my queries return results containing part of the search string. For example, in my database there are the following lines of email addresses:

ter@gmail.com

ter@hotmail.com

terrance@hotmail.com

Regardless of whether I use:

client.Search<Emails>(s => s.From(0)
                        .Size(MaximumSearchResultsSize)
                        .Query(q => q.Term( p=> p.OnField(fielname).Value(fieldValue))))

or

  client.Search<Emails>(s => s.From(0).
                              Size(MaximumPaymentSearchResults).
                              Query(q=>q.Match(p=>p.OnField(fieldName).Query(fieldValue))));                                              

My search results always return strings containing the string "partial search".

So, if I provide the search string as "ter", I still get all 3 lines. ter@gmail.com

ter@hotmail.com

terrance@hotmail.com

, , "ter". "ter@hotmail.com", "ter@hotmail.com".

, .

+4
1

, , , , , Standard Analyzer, , not_analyzed.

, API Elasticsearch

curl -XPOST "http://localhost:9200/_analyze?analyzer=standard&text=ter%40gmail.com

url, @. :

{
   "tokens": [
      {
         "token": "ter",
         "start_offset": 0,
         "end_offset": 3,
         "type": "<ALPHANUM>",
         "position": 1
      },
      {
         "token": "gmail.com",
         "start_offset": 4,
         "end_offset": 13,
         "type": "<ALPHANUM>",
         "position": 2
      }
   ]
}

, , ter gmail.com, , .

, , , , .

boolean , , , .

text ter@gmail.com, , , ter gmail.com ,

// Indexing
input: ter@gmail.com -> standard analyzer -> ter,gmail.com in inverted index

// Querying
input: ter@gmail.com -> match query -> docs with ter or gmail.com are a hit!

, , !

Term , , .. , , , ; , , , , .

// Indexing
input: ter@gmail.com -> standard analyzer -> ter,gmail.com in inverted index

// Querying
input: ter@gmail.com -> term query -> No exact matches for ter@gmail.com

input: ter -> term query -> docs with ter in inverted index are a hit!

, !

, , , , not_analyzed

putMappingDescriptor
    .MapFromAttributes()
    .Properties(p => p
        .String(s => s.Name(n => n.FieldName).Index(FieldIndexOption.NotAnalyzed)
    );

Term filter

// change dynamic to your type
var docs = client.Search<dynamic>(b => b
    .Query(q => q
        .Filtered(fq => fq
            .Filter(f => f
                .Term("fieldName", "ter@gmail.com")
            )
        )
    )
);

DSL

{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "fieldName": "ter@gmail.com"
        }
      }
    }
  }
}
+2

All Articles