根据ElasticSearch文档,我是'm attempting to add an un-analyzed version of an analyzed field, as a ' raw'多字段:https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-fields.html
这似乎是一种常见的,受到良好支持的模式 .
我创建了以下索引/字段:
{
"person": {
"aliases": {},
"mappings": {
"employee": {
"properties": {
"userName": {
"type": "string",
"analyzer": "autocomplete",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
如果我直接查询索引,即GET / person,我会看到上面发布的映射,所以我确信没有语法错误等 .
但是,当我们将数据推送到索引中时,不会创建userName.raw字段 .
{
"_index": "person",
"_type": "employee",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"username": "Test Value"
}
}
有人看到我失踪的东西吗?
谢谢!
编辑:创建我的索引时这是一个新手错误 .
PUT person
{
"person": {
"aliases": {},
"mappings": {
"employee": {
"properties": {
"email": {
请注意,人员密钥在“人员”索引中是PUT . 这创造了一个嵌套的人 .
正确的语法是删除额外的“人”
PUT person
{
"aliases": {},
"mappings": {
"employee": {
"properties": {
"email": {
请看Linoy.M.K的答案,因为他是对的 . 按ID检索记录时,不会显示“原始”字段 . 它仅作为查询的一部分有用 .
1 回答
添加多个分析器不会修改源文档意味着源文档将始终只有username而不是username.raw
添加分析器在搜索时非常有用,这意味着您现在可以使用username和username.raw进行搜索,以实现如下所示的不同行为 .