【问题标题】:elasticsearch › Problems with eliminating null values from query resultselasticsearch › 从查询结果中消除空值的问题
【发布时间】:2014-12-04 21:33:46
【问题描述】:

我正在从 elasticsearch 索引中获取数据。 我想过滤掉某些列中包含 null 或空字符串值的文档。 然而,当我使用“缺失”或“存在”方法时,我遇到了 values = "" 的一些问题,因为它们没有被过滤掉并显示在结果中

我曾想过使用通配符,但在处理 ID 中有多个单词的列时它没有给出任何结果(例如:警报描述、警报 ID 等)

使用 elasticsearch-1.3.2

我的代码缺失/存在:

{
   "query" : {
      "constant_score" : {
         "filter" : {
            "exists" : {
               "field" : "myfield"
            }
         }
      }
   }
}

我的通配符代码:

{
    query: {
     bool: {
     must: [
{
    constant_score: {
     filter: {
      missing: {
     field: trap_message.enterprise
}
}
}
}
]
     must_not: [ ]
     should: [ ]
}
}
     from: 0
     size: 10
     sort: [ ]
     facets: { }
}

【问题讨论】:

    标签: elasticsearch null wildcard


    【解决方案1】:

    我会将存在过滤器与 must_not 结合起来。这是一个搜索“authResult.address.state”字段的示例

    GET index1/type1/_search
    {
      "size": 10,
      "query": {
        "filtered": {
          "query": {
            "match_all": {}
          },
          "filter": {
            "bool": {
              "must": [
                {
                  "exists": {
                     "field": "authResult.address.state"
                  }          
                }
              ],
              "must_not": [
                 {
                     "term": {
                        "authResult.address.state": ""
                     }
                 }
              ]          
            }
          }
        }
      }
    }
    

    【讨论】:

    • 我之前尝试过,但仍然得到相同的结果
    【解决方案2】:

    当我从 GET 切换到 POST 时它起作用了

    【讨论】:

      猜你喜欢
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多