[英]Not able to insert “index”:“not_analyzed” in mapping of elasticsearch 6.1.2
我正在嘗試找到一個區分大小寫的名稱匹配項。 當我嘗試下面的代碼時,它不區分大小寫地按預期工作。
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中搜索a值時,結果為空。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.