弹性搜索“must_not”不适用于“过滤器”中的字符串

时间:2017-02-03 07:54:03

标签: elasticsearch

为什么must_not不能用于“过滤器”? (见下图)。

相同的“must_not”适用于“查询”(在图片上留言)

enter image description here

以文本形式查询:

GET _search
{
  "query": {
    "filtered": { 
     "query": {
      "bool": {
       "must": [
        {"match": {"ObjectData.PRTNAME":{"query": "1","fuzziness": "auto"}}},
        {"match": {"mostRecentVersion": true}}
       ]
     //  ,  "must_not": { "match": { "ObjectData.STATE": "ACTIVE"  }}
      }
     },
     "filter": {
       "bool": {
         "must":  [
            {"term": {"ObjectData.ISCLIENT": "1"}},
            {"term": {"mostRecentVersion": "true"}}
         ],
         "must_not": [
            { "term": {"ObjectData.PARTICIPANTTYPE": 4}},
            { "term": {"ObjectData.ISTAXRESIDENT": 0}},
            { "term": {"ObjectData.STATE": "ACTIVE"}}
         ]
       }
     }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

可能是因为您的ObjectData.STATE是一个经过分析的字符串。试试这个,它应该可以工作。

{ "term": {"ObjectData.STATE": "active"}} 

如果您想继续使用ACTIVE而不是active进行查询,则需要更改ObjectData.STATE的映射

{
    "STATE": {
       "type": "string"
    }
}

{
    "STATE": {
       "type": "string",
       "index": "not_analyzed"
    }
}

或者如果您正在使用ES 5

{
    "STATE": {
       "type": "keyword"
    }
}