0

我在 ElasticSearch 6.8 上运行。

我尝试将关键字类型字段添加到我的索引映射中。我想要的是与 my_field 的映射,如下所示:

"my_field": {
  "type": "keyword"
}

所以为了做到这一点,我在我的映射中添加了一个字段:

"properties": {
  ...
  "my_field": {
    "type": "keyword",
    "norms": false
  },
  ...
}

但目前,它给了我类似的东西:

"my_field": {
  "type": "text",
  "fields": {
    "keyword": {
      "type": "keyword",
      "ignore_above": 256
    }
  }
}

我需要这个关键字类型,因为我需要对其进行聚合,并且使用文本类型,它给了我:

默认情况下,在文本字段上禁用 Fielddata。在 [my_field] 上设置 fielddata=true 以便通过反转倒排索引将 fielddata 加载到内存中。请注意,这可能会占用大量内存。或者,改用关键字字段。

但我无法将 fielddata 设置为 true。

我尝试了很多事情,比如创建一个新索引而不是更新一个,但这些尝试都没有奏效。

  • 任何人都知道如何拥有正确的字段类型?(我更喜欢的解决方案)

  • 或者如何在映射中将 fielddata 设置为 true?

最好的问候,朱尔斯

4

1 回答 1

1

我刚刚在 Elasticsearch 6.X 版本上使用以下 curl 命令在字段上创建了 setfield-data为 true :text

curl -X POST "localhost:9200/my_index/type?pretty" -H 'Content-Type: application/json' -d'
> {
>   "mappings" :{
>   "properties": {
>     "my_field": {
>       "type":     "text",
>       "fielddata": true
>     }
>   }
>   }
> }'

它创建了具有适当映射的索引。

{
  "_index" : "my_index",
  "_type" : "type",
  "_id" : "3Jl0F3EBg44VI1hJVGnz",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

映射 API 给出以下 JSON 响应。

{
  "my_index": {
    "mappings": {
      "type": {
        "properties": {
          "mappings": {
            "properties": {
              "properties": {
                "properties": {
                  "my_field": {
                    "properties": {
                      "fielddata": {
                        "type": "boolean"
                      },
                      "type": {
                        "type": "text",
                        "fields": {
                          "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
于 2020-03-26T15:29:01.147 回答