0

通过电子邮件完全匹配的确切javascript elasticsearch client.search-param 是什么?

我尝试了很多变体,但在我的测试数据(只有一个文档)上,即使通过“aa@bb.cc”,我也总是得到该文档的匹配项。

鉴于此映射:

curl -X GET 'http://localhost:9200/entity/user/_mapping?pretty'

"entity" : {
    "mappings" : {
      "user" : {
        "properties" : {
          "created_at" : {
            "type" : "long"
          },
          "email" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "login_token" : {
            "properties" : {
              "created_at" : {
                "type" : "long"
              },
              "email" : {
                "type" : "string"
              },
              "expires_at" : {
                "type" : "long"
              },
              "merchant_id" : {
                "type" : "string"
              },
              "token" : {
                "type" : "string"
              }
            }
          }
        }
      }
    }
  }
}

文件:

curl -X GET 'http://localhost:9200/entity/user/_search?pretty'

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "entity",
      "_type" : "user",
      "_id" : "VzUs-y7QRUCUqr3SBuB-FQ",
      "_score" : 1.0,
      "_source":{"email":"gnimmelf@gmail.com"}
    } ]
  }
}

更新:尝试了@progrrammer 的建议:

user_email = "asafs@asfasf.afasfa"

res = yield client.search({
  index: index,
  type: type,
  query : {
    term: {
       email: user_email
    }
  }
})

仍然给出了血腥相同的结果:

-> POST http://localhost:9200/entity/user/_search?query=

<- 200
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "entity",
        "_type": "user",
        "_id": "JUieGEOAQxeU2pc7HMieeQ",
        "_score": 1,
        "_source": {
          "email": "gnimmelf@gmail.com",
...

更新2:这有效

res = yield client.search({
  index: index,
  type: type,
  q: 'email='+user_email
})

所以不知何故,官方的 js 客户端被 / 搞砸了。伙计,我受够了 Elasticsearch ......

4

1 回答 1

0

只需使用termQuerytermFilter

匹配具有包含术语的字段的文档。

{
    "query": {
        "term": {
           "email":"gnimmelf@gmail.com"
        }
    }
}
于 2014-08-14T13:40:27.000 回答