简体   繁体   English

如何在 ElasticSearch 中使用通配符以多种方式索引同一字段

[英]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.

相关问题 如何查询 ElasticSearch 索引中另一个数字字段的确切文本字段并过滤术语? - How does one query an exact text-field and filter terms on another number-field in an ElasticSearch Index? 如何在快照中找到 Elasticsearch 索引? - How to find Elasticsearch index in snapshot? AWS Rekognition - 如何索引属于同一张脸的多个图像? - AWS Rekognition - How to index multiple images belonging to the same face? 如何停止Amazon Elasticsearch服务的索引? - How to stop an index of Amazon Elasticsearch service? 如何使用Amazon Elasticsearch对动态数据进行索引? - How to use Amazon Elasticsearch to index dynamodb data? AWS中的ElasticSearch通配符查询和空格问题 - Issue with ElasticSearch wildcard query and spaces in AWS AWS Elasticsearch 和 Cognito - 如何允许 Cognito 用户创建私有索引? - AWS Elasticsearch and Cognito - How to allow Cognito user to create private index? 如何全天自动创建 elasticsearch 索引模式? - How to automate the creation of elasticsearch index patterns for all days? 如何仅将 1 个索引从 ElasticSearch 集群迁移到 OpenSearch 集群? - How to migrate only 1 index from ElasticSearch cluster to OpenSearch cluster? ElasticSearch索引,更新API - ElasticSearch Index, Update APIs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM