在java elasticsearch上设置字段数据= true [英] set field data = true on java elasticsearch

查看:475
本文介绍了在java elasticsearch上设置字段数据= true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Eclipse运行Java弹性搜索查询。在测试该错误时遇到此错误,并且在API中找不到任何告诉我如何将该字段数据设置为true的错误

Running a java elastic search query through Eclipse. Getting this error when I am testing it, and I can't find anywhere in the API that tells me how I can set this field data to true


IllegalArgumentException [默认情况下
禁用文本字段上的字段数据。在[created]上设置fielddata = true,以通过反转反相索引将字段数据加载到
内存中。请注意,这可能会使
使用大量内存。或者,使用关键字字段代替。]

IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [created] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.]

有人知道我可以解决这个问题吗?

Does anyone know how I can fix this?

推荐答案

您必须修改索引映射属性:

You must modify index mapping properties:

try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
    final XContentBuilder builder = jsonBuilder
            .startObject()
              .startObject("your_type")
                .startObject("properties")
                  .startObject("your_field")
                    .field("type", "text")
                    .field("fielddata", true)/*setting fielddata*/
                  .endObject()
                .endObject()
              .endObject()
            .endObject();

    client.admin().indices().preparePutMapping("your_index")
            .setType("your_type")
            .setSource(builder)/*also there are overloads for setSource()*/
            .get();
}

OR

String source = "{\"your_type\":{\"properties\":{\"your_field\":{\"type\":\"text\",\"fielddata\":true}}}}";
client.admin().indices().preparePutMapping("your_index)
        .setType("your_type")
        .setSource(source, XContentType.JSON)
        .get();

结果:

{
  "your_index": {
    "aliases": {},
    "mappings": {
      "your_type": {
        "properties": {
          ...
          ...
          "your_field": {
            "type": "text",
            "fielddata": true,
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
          ...
          ...
        }
      }
    }
  }
}

这篇关于在java elasticsearch上设置字段数据= true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆