【问题标题】:Can't get email field to index correctly in ElasticSearch无法在 ElasticSearch 中正确索引电子邮件字段
【发布时间】:2015-03-16 02:41:20
【问题描述】:

我正在尝试设置一个电子邮件字段以在我的映射中正确索引。

因为我不希望 email 在被索引时被标记化,所以我之前指定了以下映射以允许它仅在整个字符串匹配时匹配搜索。

{
  "users": {
    "mappings": {
      "user": {
        "properties": {
          "email": {
            "type": "string",
            "index": "not_analyzed"
          },
          "name": {
            "type": "string",
            "fields": {
              "raw": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "nickname": {
            "type": "string"
          }
        }
      }
    }
  }
}

除了我希望将 emailnickname 字段作为小写进行比较之外,此方法有效。

我尝试了几种方法来指定更改映射以使用小写标记过滤器。

我已经通过以下方式做到了这一点:

{
  "settings":{
    "index":{
      "analysis":{
        "analyzer":{
          "lowercase_analyzer":{
            "tokenizer":"standard", //Also tried 'Simple' and 'Keyword'
            "filter":"lowercase"
          }
        }
      }
    }
  },

  "mappings": {
    "user": {
      "properties": {
        "email": {
          "type": "string",
          "analyzer":"lowercase_analyzer",
          "index": "not_analyzed" //Tried with and without this
        },
        "name": {
          "type": "string",
          "analyzer":"lowercase_analyzer",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "nickname": {
          "type": "string",
          "analyzer": "lowercase_analyzer"
        }
      }
    }
  }
}

我希望允许以下行为:

  • 电子邮件可以作为小写进行搜索和比较,并且只有在整个电子邮件匹配时才应该匹配
  • name是多字段,用于搜索和排序,使用小写
  • 昵称比较小写

【问题讨论】:

    标签: mongodb elasticsearch mongoose elasticsearch-plugin


    【解决方案1】:

    您可以尝试以下方法,看看是否符合您的要求 - {

      "settings":{
         "index":{
            "analysis":{
               "analyzer":{
                  "flat":{
                     "tokenizer":"keyword",
                     "filter":"lowercase"
                  }
               }
            }
         }
        },
    
        "mappings": {
         "user": {
            "properties": {
               "email": {
                 "type": "string",
                 "analyzer":"flat"
               },
               "name": {
                  "type": "string",
                   "fields": {
                      "raw": {
                        "type": "string",
                        "index": "not_analyzed"
                      }
                    }
               },
               "nickname": {
                  "type": "string"
               }
            }
         }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2021-05-16
      • 2017-03-09
      • 2020-01-06
      相关资源
      最近更新 更多