我正在尝试找到一个符合案例敏感的匹配名称。当我尝试以下代码时,它对病例不敏感的预期工作。
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();
为了找到情况敏感值,我发现将索引使用为not_analyzed使用。我尝试了以下
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();
我得到了一个例外,如下所示
java.lang.IllegalArgumentException: Could not convert [GroupName.index] to boolean
我想完成下面的两个方案:
1. Find by case sensitive
2. Find by case insensitive.
弹性搜索版本为6.1.2。
任何帮助都非常感谢。
update-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();
现在我可以插入。但是,当我在groupName中搜索一个值时,结果为空。
not_analyzed
已弃用,您需要改用keyword
。
尝试以下此映射,而是:
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