elasticsearch index mapping

时间:2017-05-04 15:49:26

标签: java elasticsearch

我需要使用jest和传输客户端创建和更新索引映射,但是当我尝试使用本教程时https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin-indices.html#java-admin-indices-create-index-settings 我有这个问题:

  

此行有多个标记    - 令牌上的语法错误")",删除此令牌    - 令牌上的语法错误"。",@期望后的预期

这是我的代码:

Client client = new PreBuiltTransportClient(settings)
                            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

        IndicesAdminClient indicesAdminClient = client.admin().indices();

        indicesAdminClient.prepareCreate("calls")
      .setSettings(Settings.builder()             
              .put("index.number_of_shards", 10)
      )
      .addMapping("call", "{\n" +
              "      \"properties\": {\n" +
              "        \"id\": {\n" +
              "          \"type\": \"string\"},\n" +
              "        \"number\": {\n" +
              "          \"type\": \"string\"},\n" +
              "        \"name\": {\n" +
              "          \"type\": \"string\"}\n" +
              "      }\n" +
              "  }")     
      .get();              

        String json = "{" +

              "\"id\":\"1\"," +
              "\"number\":\"123333333\"," +
              "\"name\":\"Sharon Tries Elastic\"" +
          "}";

    IndexResponse response = client.prepareIndex("calls", "call")
            .setSource(json)
            .get();

    // Index name
    String _index = response.getIndex();
    // Type name
    String _type = response.getType();
    // Document ID (generated or not)
    String _id = response.getId();
    // Version (if it's the first time you index this document, you will get: 1)
    long _version = response.getVersion();

} 可以帮忙 谢谢

0 个答案:

没有答案
相关问题