elasticsearch-6 - Elasticsearch:使用日期过滤器为同一字段传递多个值
问题描述
我正在根据给定字段的多个值搜索员工详细信息,即将为给定请求传递多个员工电子邮件地址/姓名以及多个国家/地区。现在,我们需要提取这些员工的所需详细信息(基于姓名、电子邮件地址和他们各自的国家/地区)。
查询适用于单个字段值搜索,例如员工姓名或员工电子邮件地址、国家和日期范围。但是,它无法通过员工姓名或电子邮件地址、国家和日期范围的多个值获得所需的响应。
以下是索引映射详细信息:
{
emplsampleindex: {
mappings: {
employeeinfo: {
properties: {
emp_cntry: { type: "keyword" },
employee_name: { type: "text",
fields: { keyword: { type: "keyword" } } },
email_address: { type: "keyword"},
hiredate: { type: "date", format: "yyyy-MM-dd" }
}
}
}
}
}
使用单个值:
{
"bool" : {
"must" : [
{
"match" : {
"email_address" : {
"query" : "raju@test.com",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 1.0
}
}
}
],
"filter" : [
{
"range" : {
"hiredate" : {
"from" : "2013-08-01",
"to" : null,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
不使用多个值: :
{
"bool": {
"filter": [
{
"range": {
"hiredate": {
"from": "2013-08-01",
"to": null,
"boost": 1.0
}
}
}
],
"should": [
{
"term": {
"email_address": {
"value": "tempemail1@test.com",
"boost": 1.0
}
}
},
{
"term": {
"email_address": {
"value": "temp@test.com",
"boost": 1.0
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
使用should,我们将在 elasticsearch 中获取 2013 年 8 月 1 日的所有员工记录,而不是should,如果我使用must ,那么尽管我们有这些 email_address 的记录,但我们没有得到任何结果,即总点击数。
解决方案
推荐阅读
- selenium - 当他单击硒中的“返回顶部”按钮时如何验证用户已滚动到顶部
- python - 了解 Python 中的对象类型
- python - 如何从这些数据创建函数?
- c# - 在 c# 中保存/加载 HttpClient 的“浏览器”会话
- java - 休眠条件.setFetchSize 不起作用
- r - 什么是用于 k-means 初始化的 NbClust 方法?
- mysql - 错误 2002 (HY000): 无法通过 ubuntu 服务器中的套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器
- swift - Swift 中的计算属性和存储值属性有什么区别?
- laravel - Laravel 自定义密码邮箱
- sql - 查询内的多个替换