[英]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 字段中看到有两种解释:
在文本标准标记器是工作并将标记保存到您的索引。 这意味着您可以找到术语 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.