elasticsearch,case-sensitive,case-insensitive,elasticsearch-6,Java,elasticsearch,Case Sensitive,Case Insensitive,Elasticsearch 6" /> elasticsearch,case-sensitive,case-insensitive,elasticsearch-6,Java,elasticsearch,Case Sensitive,Case Insensitive,Elasticsearch 6" />

Java 不能插入“;索引";:&引用;“未分析”;在elasticsearch 6.1.2的映射中

Java 不能插入“;索引";:&引用;“未分析”;在elasticsearch 6.1.2的映射中,java,elasticsearch,case-sensitive,case-insensitive,elasticsearch-6,Java,elasticsearch,Case Sensitive,Case Insensitive,Elasticsearch 6,我正在尝试查找一个名称与大小写敏感的匹配项。当我尝试下面的代码时,它在不区分大小写的情况下正常工作 HashMap<String, String> data = new HashMap<String, String>(); data.put("GroupId", "3"); data.put("GroupName", "testGroup three"); data.put("CreatedDateTime"

我正在尝试查找一个名称与大小写敏感的匹配项。当我尝试下面的代码时,它在不区分大小写的情况下正常工作

        HashMap<String, String> data = new HashMap<String, String>();
        data.put("GroupId", "3");
        data.put("GroupName", "testGroup three");
        data.put("CreatedDateTime", "20180115130026757+0000");
        data.put("UpdatedDateTime", "20180115130026757+0000");
        data.put("Createdby", "3");
        data.put("GroupUser",  "{1,2,3,4}");
        data.put("status", "active");

        String mapping = {"typename":{"properties":{
        "GroupName":{"type":"text","index":"not_analyzed"},
        "Createdby":{"type":"text","index":"not_analyzed"},
        "GroupUser":{"type":"text","index":"not_analyzed"},
        "UpdatedDateTime":{"type":"text","index":"not_analyzed"},
        "CreatedDateTime":{"type":"text","index":"not_analyzed"},
        "GroupId":{"type":"text","index":"not_analyzed"},
        "status":{"type":"text","index":"not_analyzed"}}}}

        client = new PreBuiltTransportClient(settings).addTransportAddresses(new TransportAddress(new InetSocketAddress(ipaddress, port)));

        //inserting record
        IndexResponse response = client.prepareIndex(indexName, typeName).setSource(data).get();

        //inserting mapping
        client.admin().indices().preparePutMapping(indexName)
        .setType("typeName")
        .setSource(mapping, XContentType.JSON)
        .get();
我想完成以下两个场景:

 1. Find by case sensitive
 2. Find by case insensitive.
弹性搜索版本是6.1.2

非常感谢您的帮助

更新-1

根据@Val,我已将代码更改为:

    HashMap<String, String> data = new HashMap<String, String>();
    data.put("GroupId", "3");
    data.put("GroupName", "testGroup three");
    data.put("CreatedDateTime", "20180115130026757+0000");
    data.put("UpdatedDateTime", "20180115130026757+0000");
    data.put("Createdby", "3");
    data.put("GroupUser",  "{1,2,3,4}");
    data.put("status", "active");

    String mapping = {"typename":{"properties":{
    "GroupName":{"type":"keyword"},
    "Createdby":{"type":"keyword"},
    "GroupUser":{"type":"keyword"},
    "UpdatedDateTime":{"keyword":"text"},
    "CreatedDateTime":{"keyword":"text"},
    "GroupId":{"type":"keyword"},
    "status":{"type":"keyword"}}}}

    client = new PreBuiltTransportClient(settings).addTransportAddresses(new TransportAddress(new InetSocketAddress(ipaddress, port)));

   client.admin().indices().prepareCreate("indexName").get(); 

    //inserting mapping
    client.admin().indices().preparePutMapping(indexName)
    .setType("typeName")
    .setSource(mapping, XContentType.JSON)
    .get();

    //inserting record
    IndexResponse response = client.prepareIndex(indexName, typeName).setSource(data).get();
HashMap data=newhashmap();
数据。put(“GroupId”,“3”);
data.put(“组名”、“测试组三”);
数据输入(“CreatedDateTime”,“20180151130026757+0000”);
数据输入(“更新日期时间”,“20180151130026757+0000”);
数据。put(“Createdby”,“3”);
put(“GroupUser”,“{1,2,3,4}”);
数据输入(“状态”、“活动”);
字符串映射={“类型名”:{“属性”:{
“组名”:{“类型”:“关键字”},
“Createdby”:{“类型”:“关键字”},
“GroupUser”:{“类型”:“关键字”},
“UpdateDateTime”:{“关键字”:“文本”},
“CreatedDateTime”:{“关键字”:“文本”},
“GroupId”:{“类型”:“关键字”},
“状态”:{“类型”:“关键字”}}
client=新的预构建TransportClient(设置).addTransportAddresses(新的TransportAddress(新的InetSocketAddress(ipaddress,端口));
client.admin().index().prepareCreate(“indexName”).get();
//插入映射
client.admin().index().preparePutMapping(indexName)
.setType(“类型名称”)
.setSource(映射,XContentType.JSON)
.get();
//插入记录
IndexResponse-response=client.prepareIndex(indexName,typeName).setSource(data).get();

现在我可以插入。但是当我在GroupName中搜索a值时,结果是空的。

未被分析
被弃用,您需要使用
关键字

请尝试以下映射:

String mapping = {
  "typename": {
    "properties": {
      "GroupName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "Createdby": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "GroupUser": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "UpdatedDateTime": {
        "type": "date",
        "format": "yyyyMMddHHmmssSSSZ"
      },
      "CreatedDateTime": {
        "type": "date",
        "format": "yyyyMMddHHmmssSSSZ"
      },
      "GroupId": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "status": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}
还要确保在插入数据之前放置映射,即

执行:

//inserting mapping
之前:

//inserting record

您还可以使用
数据
变量中的任何内容更新您的问题吗?@Val我已更新了数据变量的问题。好的,然后尝试下面的答案,但请确保先删除索引:-)请检查我更新的问题。当我尝试键入关键字时。我看到不同类型的映射器[CreatedDateTime],当前类型[text],合并类型[keyword]请确保先删除索引,这是相同的。日期字段的映射不正确。查看我的更新答案如果我在编制索引之前进行映射,我将得到
无此类索引
错误。
//inserting mapping
//inserting record