簡體   English   中英

使用 elasticsearch js 中的術語

[英]using terms in elasticsearch js

由於 Elasticsearch 有精彩的文檔,我無法找出搜索術語的正確語法,這是我的代碼:

  let checkuser = await client.search({
        index: "users",
        type: "my_users",
        body: {
          query: {
            term: {
              email: req.body.email
            }
          }
        }
      });

I wish to search for an object that has a key value pair of 'email' with a certain email, but I wish it to be the exact email I wrote, if its a@mail.com ab@mail.com should not match,我知道我需要使用術語,但是當我這樣寫它不起作用時,我的語法有什么問題?

PS這是我的索引映射:

  "users" : {
    "mappings" : {
      "jobix_users" : {
        "properties" : {
          "confirmed" : {
            "type" : "boolean"
          },
          "email" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "firstName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "jobNotification" : {
            "type" : "boolean"
          },
          "jobTitle" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "lastName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "password" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "userName" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }

您使用默認映射,這意味着您在索引文檔時使用標准標記器。

如何在映射 email 字段中看到有兩種解釋:

  1. 文本
  2. 關鍵詞

在文本標准標記器是工作並將標記保存到您的索引。 這意味着您可以找到術語 alex 和術語 mail.com。 如果您想查找整個 email 那么您的查詢應如下所示:

{
    "query": {
        "term": {
            "email.keyword": req.body.email
        }
    }
}   

但是 elasticsearch 具有用於 url 和郵件的特殊uax_url_email 標記器。 我想建議將此標記器用於 email 字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM