amazon-web-services - 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:
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.
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.
解决方案
您可以使用多字段以多种方式对字段进行索引name
。修改后的索引映射将是
{
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ngram_analyzer",
"search_analyzer": "keyword_analyzer",
"fields": {
"raw": {
"type": "wildcard"
},
"keyword": {
"type": "keyword"
}
}
}
}
}
}
现在您可以name
用于基于文本的搜索、name.raw
通配符搜索、name.keyword
关键字搜索
推荐阅读
- grails - 为什么 grails 源不在 /src 文件夹中?
- java - java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider 在运行 Selenium-Cucumber 测试时
- grammar - 语法中空格方法ws的默认定义
- html - 如何将 swf 文件嵌入到网站上的浮动 iframe 中。书签?
- python - 使用 re 替换数组的一部分
- sql-server - 尝试使用 SQL Server 后端分发访问应用程序
- django - 为什么迁移不起作用,它既不会在 django 应用程序中创建迁移目录
- android - 在android中滚动底部工作表的问题
- c# - 如何仅 Ping IPv4?
- python - 如何以真正的并发方式运行多个 PyQt QTimers?