[英]Multi field text and keyword fields in elasticsearch
I'm looking into switching from solr to elasticsearch and have indexed a bunch of documents into it without providing a schema/mapping and a lot of the fields that i would have previously set as indexed strings in solr have been set as both text and keyword fields using multi-fields . 我正在考虑从solr切换到elasticsearch并将一堆文档编入其中而不提供模式/映射,并且我之前在solr中设置为索引字符串的许多字段已被设置为text和keyword使用多字段的字段 。
Is there any benifit to having a keyword field also as a text field using multi-fields ? 将关键字字段作为使用多字段的文本字段有什么好处吗? in my case most values in fields are single words so i'd imagine it wouldn't matter if they are sent to the analyzer but the es docs seem to imply that keyword fields are not considered when searching or at least treated differently?
在我的情况下,字段中的大多数值都是单个单词,所以我想如果将它们发送到分析器并不重要但是es文档似乎暗示在搜索时不考虑关键字字段或者至少采用不同的处理方式?
Just to expand on that a little further if i search for the term "ipad" would a document score higher if it had "ipad" in a keyword field as well as some other text field vs the same document without the keyword field? 只是为了进一步扩展,如果我搜索术语“ipad”,如果在关键字字段中有“ipad”以及其他文本字段与没有关键字字段的同一文档,文档得分会更高吗? and if say "ipad" was only in a keyword field would the document still match?
如果说“ipad”仅在关键字字段中,那么文档是否仍然匹配?
To answer my own question i created a quick test, pretty much keyword and text fields are equivalent when searching and multi-fields seem to get the same score as their primary type so i guess the second field has no effect on search scoring 为了回答我自己的问题,我创建了一个快速测试,几乎关键字和文本字段在搜索时是等效的,多字段似乎得到与其主要类型相同的分数,所以我猜第二个字段对搜索评分没有影响
Weirdly a multi word value in both keyword and text fields got the same score which i would have expecting the keyword field to score lower or not at all but for my purposes that is fine so i'm not going to investigate it further. 奇怪的是,关键字和文本字段中的多字值得到了相同的分数,我希望关键字字段得分较低或根本没有,但为了我的目的,这很好,所以我不打算进一步调查。
PUT test_index
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"test_type" : {
"properties" : {
"multifield": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"keywordfield": {
"type": "keyword"
},
"textfield": {
"type": "text"
}
}
}
}
}
POST /_bulk
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 1 }
{ "doc" : { "multifield" : "ipad" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 2 }
{ "doc" : { "keywordfield" : "ipad" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 3 }
{ "doc" : { "keywordfield" : "a green ipad" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 4 }
{ "doc" : { "textfield" : "a yellow ipad" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 5 }
{ "doc" : { "keywordfield" : "ipad", "textfield" : "ipad" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 6 }
{ "doc" : { "keywordfield" : "unrelated", "textfield" : "hopefully this wont show up" }, "doc_as_upsert" : true }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": 7 }
{ "doc" : { "textfield" : "ipad" }, "doc_as_upsert" : true }
GET /test_index/_search?q=ipad
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 6,
"max_score": 0.28122374,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "5",
"_score": 0.28122374,
"_source": {
"keywordfield": "ipad",
"textfield": "ipad"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_score": 0.2734406,
"_source": {
"multifield": "ipad"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"_score": 0.2734406,
"_source": {
"keywordfield": "ipad"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "7",
"_score": 0.2734406,
"_source": {
"textfield": "ipad"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "3",
"_score": 0.16417998,
"_source": {
"keywordfield": "a green ipad"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "4",
"_score": 0.16417998,
"_source": {
"textfield": "a yellow ipad"
}
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.