首页 > 解决方案 > 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 的记录,但我们没有得到任何结果,即总点击数。

标签: elasticsearch-6

解决方案


推荐阅读