elasticsearch ElasticSearch中的嵌套布尔和过滤器查询,elasticsearch,kibana,elasticsearch,Kibana" /> elasticsearch ElasticSearch中的嵌套布尔和过滤器查询,elasticsearch,kibana,elasticsearch,Kibana" />

elasticsearch ElasticSearch中的嵌套布尔和过滤器查询

elasticsearch ElasticSearch中的嵌套布尔和过滤器查询,elasticsearch,kibana,elasticsearch,Kibana,我有一些嵌套字段的简历索引。我正在运行下面的代码来获取简历,这些简历在他们的技能中有Ruby,在他们的教育中有计算机 GET /resume/candidates/_search { "query": { "nested" : { "path" : "sections", "query" : { "bool" : { "must": [

我有一些嵌套字段的简历索引。我正在运行下面的代码来获取简历,这些简历在他们的技能中有Ruby,在他们的教育中有计算机

GET /resume/candidates/_search
{
    "query": {
        "nested" : {
            "path" : "sections",
            "query" : {
                "bool" : {
                  "must": [
                    {"match": {"sections.skills": "Ruby"}}
                  ], 
                    "filter" : [
                    { "term" : {"sections.education": "computer"} }
                    ]
                }
            }
        }
    }
}
当我分别运行bool和filter查询时,它们会给出正确的结果。然而,当我把它们结合在一起时,它们不会产生任何结果。在我的索引中有一份关于红宝石技能和计算机教育的简历

GET /resume/candidates/_search
{
    "query": {
        "nested" : {
            "path" : "sections",
            "query" : {
                "bool" : {
                  "must": [
                    {"match": {"sections.skills": "Ruby"}}
                  ], 
                    "filter" : [
                    { "term" : {"sections.education": "computer"} }
                    ]
                }
            }
        }
    }
}
或者,目前我将离开分数部分,并将两者置于相同的条件下,如下所示:

GET /resume/candidates/_search
{
    "query": {
        "nested" : {
            "path" : "sections",
            "query" : {
                "bool" : {
                  "must": [
                    {"match": {
                      "sections.skills": "Ruby"}},

                    {"match": {
                      "sections.education": "computer"}}

                  ]
               }
            }
        }
    }
}

它仍然不会返回任何结果,但如果单独编写,它会返回结果。有人能帮忙吗?

有你的地图就好了。顺便说一句,我尝试使用以下代码创建您的场景,查询工作正常:

首先定义映射

PUT resume
{
  "mappings": {
    "candidates": {
      "properties": {
        "sections": {
          "type": "nested",
          "properties": {
            "skills": {
              "type": "text"
            },
            "education": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
然后添加两个候选项:

PUT resume/candidates/1
{
  "sections": [
    {
      "skills": "Ruby",
      "education": "computer"
    },
    {
      "skills": "elastic",
      "education": "computer"
    }
  ]
}


PUT resume/candidates/2
{
  "sections": [
    {
      "skills": "kibana",
      "education": "computer"
    },
    {
      "skills": "elastic",
      "education": "computer"
    }
  ]
}
以下是查询:

GET resume/candidates/_search
{
  "query": {
    "nested": {
      "path": "sections",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "sections.education": {
                  "value": "computer"
                }
              }
            },
            {
              "match": {
                "sections.skills": "Ruby"
              }
            }
          ]
        }
      }
    }
  }
}
它只返回第一个日期:

{
  "took": 11,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.87546873,
    "hits": [
      {
        "_index": "resume",
        "_type": "candidates",
        "_id": "1",
        "_score": 0.87546873,
        "_source": {
          "sections": [
            {
              "skills": "Ruby",
              "education": "computer"
            },
            {
              "skills": "elastic",
              "education": "computer"
            }
          ]
        }
      }
    ]
  }
}

您是在寻找一个同时具有这两种或其中之一的结果吗?@GrumpyCrouton需要同时更改查询结构。包含两个嵌套查询的布尔查询。@MohammadMazraeh我不能这样做。如果分数在bool查询内,则会影响分数。“它需要过滤掉。”MohammadMazraeh我也试过了。没用。你能查一下我的新密码吗?