Why does ElasticSearch match a query that returns all results?

I have the following ElasticSearch query, which, I think, will return all matches in the email field , where it is equal to myemails@email.com

"query": {
  "bool": {
    "must": [
      {
        "match": {
          "email": "myemail@gmail.com"
      }
    }
  ]
}

}

The mapping for the type of user that is being searched is as follows:

    {
      "users": {
      "mappings": {
         "user": {
            "properties": {
               "email": {
                  "type": "string"
               },
               "name": {
                  "type": "string",
                  "fields": {
                     "raw": {
                        "type": "string",
                        "index": "not_analyzed"
                     }
                  }
               },
               "nickname": {
                  "type": "string"
               },
            }
         }
       }
   }  
     }

Below is an example of the results obtained from ElasticSearch

 [{
    "_index": "users",
    "_type": "user",
    "_id": "54b19c417dcc4fe40d728e2c",
    "_score": 0.23983537,
    "_source": {
    "email": "johnsmith@gmail.com",
    "name": "John Smith",
    "nickname": "jsmith",
 },
 {
    "_index": "users",
    "_type": "user",
    "_id": "9c417dcc4fe40d728e2c54b1",
    "_score": 0.23983537,
    "_source": {
       "email": "myemail@gmail.com",
       "name": "Walter White",
       "nickname": "wwhite",
 },
 {
    "_index": "users",
    "_type": "user",
    "_id": "4fe40d728e2c54b19c417dcc",
    "_score": 0.23983537,
    "_source": {
       "email": "JimmyFallon@gmail.com",
       "name": "Jimmy Fallon",
       "nickname": "jfallon",
}]

From the above query, I would think that the value of the email property should be an exact match with ' myemail@gmail.com '.

How the ElasticSearch DSL query should be executed in order to return only exact matches in the email .

+4
1

, . , ,

"myemail@gmail.com" = > [ "myemail", "gmail.com" ]

, myemail gmail.com, . , john@gmail.com, . ,

"john@gmail.com" = > [ "john", "gmail.com" ]

"gmail.com" , .

, ; not_analyzed. , .

"not_analyzed"

"john@gmail.com" = > [ "john@gmail.com" ]

, -

{
  "users": {
    "mappings": {
      "user": {
        "properties": {
          "email": {
            "type": "string",
            "index": "not_analyzed"
          },
          "name": {
            "type": "string",
            "fields": {
              "raw": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "nickname": {
            "type": "string"
          }
        }
      }
    }
  }
}

.

+9

Source: https://habr.com/ru/post/1570813/


All Articles