[英]How index the same field in multiple ways with wildcard in ElasticSearch
I have the below mappings for a field ("name"):我有一个字段(“名称”)的以下映射:
"name": {
"analyzer": "ngram_analyzer",
"search_analyzer": "keyword_analyzer",
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
It works fine and allows to search as both text and keyword.它工作正常,允许作为文本和关键字进行搜索。 As per the ES documentation:
根据 ES 文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html A string field could be mapped as a text field for full-text search and as a keyword field for sorting or aggregation. https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html字符串字段可以映射为全文搜索的文本字段和排序或聚合的关键字字段。
But I am trying to extend this mapping to also support wildcard search.但我正在尝试扩展此映射以支持通配符搜索。
I tried to modify the mapping(for eg. like below) but couldn't get it working.我试图修改映射(例如,如下所示)但无法正常工作。
"name": {
"analyzer": "ngram_analyzer",
"search_analyzer": "keyword_analyzer",
"type": "text",
"fields": [{
"raw": {
"type": "wildcard"
}
}, {
"type": "keyword"
}]
}
Also tried with,也试过了,
"name": {
"analyzer": "ngram_analyzer",
"search_analyzer": "keyword_analyzer",
"type": "text",
"fields": [{
"raw": {
"type": "wildcard"
}
}, {"raw": {
"type": "keyword"
}}]
}
How should the mapping look like to allow name to be searched as text, keyword and wildcard.映射应该如何允许名称作为文本、关键字和通配符进行搜索。
You can use multi-fields to index the name
field in multiple ways.您可以使用多字段以多种方式索引
name
字段。 Modified index mapping will be修改后的索引映射将是
{
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ngram_analyzer",
"search_analyzer": "keyword_analyzer",
"fields": {
"raw": {
"type": "wildcard"
},
"keyword": {
"type": "keyword"
}
}
}
}
}
}
Now you can use name
for text-based search, name.raw
for wildcard search, name.keyword
for keyword search现在您可以使用
name
进行基于文本的搜索, name.raw
进行通配符搜索, name.keyword
进行关键字搜索
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.