【问题标题】:Elastic Search boolquery still shows resultElastic Search boolquery 仍然显示结果
【发布时间】:2018-05-17 07:18:27
【问题描述】:

我正在尝试在 Elastic Search 中使用查询,其中忽略了所有 English("taal":"engels") 书籍。 我想我应该使用 bool 查询和 must_not,条件是查询中的“taal”:“Engels”。

GET books/_search
{
  "query": { 
    "bool": { 
      "must_not" : {
        "term" : { "taal" : "Engels" }
      }
    }
  }
}

但是,在 Kibana 中运行此查询时,它仍会显示语言 = 英语的结果。

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 501,
    "max_score": 1,
    "hits": [
      {
        "_index": "producten4",
        "_type": "boek",
        "_id": "9780582401815",
        "_score": 1,
        "_source": {
          "isbn": "9780582401815",
          "hoofdtitel": "Forrest Gump",
          "taal": "Engels",
        }
      },
      ETCETERA....
    ]
  }
}

字段 taal 的映射:

"taal": {
  "type": "text",
  "fields": {
    "keyword": {
      "type": "keyword",
      "ignore_above": 256
    },
    "raw": {
      "type": "keyword"
    },
    "taal": {
      "type": "text"
    }
  }
}

【问题讨论】:

    标签: elasticsearch boolean kibana


    【解决方案1】:

    尝试使用“匹配”而不是“术语”?

    【讨论】:

      【解决方案2】:

      我已通过将 .raw 添加到字段名来修复它:

      bool: {
          must_not: [
            {
              term: {
                'taal.raw': 'Engels',
              }
            },
            {
              term: {
                'taal.raw': 'Nederlands',
              }
            }]
          }
      

      【讨论】:

        猜你喜欢
        • 2022-12-16
        • 2014-12-16
        • 1970-01-01
        • 1970-01-01
        • 2018-01-15
        • 1970-01-01
        • 1970-01-01
        • 2017-12-29
        • 2017-08-16
        相关资源
        最近更新 更多