【问题标题】:Elasticsearch keyword with spaces in term query on keywordElasticsearch 关键字在关键字的术语查询中带有空格
【发布时间】:2017-07-10 14:40:31
【问题描述】:

我有以下映射:

{
  "events": {
    "mappings": {
      "event": {
        "Type of Event": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

以及索引里面的如下数据

{
  "Type of Event": "Orientation Session"
},
{
  "Type of Event": "Orientation Tutorial"
}

我正在尝试仅匹配具有Type of Event == "Orientation Session" 的那些。

我正在尝试以下查询:

{
  "query": {
    "term": {
      "Type of Event.keyword": "Orientation Session"
    }
  }
}

但它不匹配任何东西。但是,如果字符串中没有空格,它确实有效。我不能在这里使用match 查询,因为它会匹配这两个事件。

我做错了什么?我在术语查询中看到了很多关于空格的讨论,但没有关于使用keyword 的讨论。它们都特定于 elasticsearch 2.0。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    问题是您的映射错误,您缺少properties 关键字。

    如果您尝试使用您提供的映射创建索引,您应该会收到以下错误:

    unknown setting [index.events.mappings.event.Type of Event.fields.keyword.ignore_above] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
    

    所以你需要改用以下映射,它会起作用:

    {
      "mappings": {
        "event": {
          "properties": {             <--- this was missing
            "Type of Event": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多