【问题标题】:Index email with ElasticSearch - mapping problem使用 ElasticSearch 索引电子邮件 - 映射问题
【发布时间】:2021-05-16 00:40:50
【问题描述】:

我使用 ES v7。我想用 ElasticSearch 索引电子邮件地址,但使用 uax_url_email 标记器。 我想用完整的电子邮件地址搜索 Elastic。

我尝试使用此映射:

PUT /test
{
  "settings": {
    "analysis": {
      "filter": {
        "email": {
          "type": "pattern_capture",
          "preserve_original": 1,
          "patterns": [
            "([^@]+)",
            "(\\p{L}+)",
            "(\\d+)",
            "@(.+)",
            "([^-@]+)"
          ]
        }
      },
      "analyzer": {
        "email": {
          "tokenizer": "uax_url_email",
          "filter": [
            "email",
            "lowercase",
            "unique"
          ]
        }
      }
    }
  },
  "mappings": {
    "emails": {
      "properties": {
        "email": {
          "type": "string",
          "analyzer": "email"
        }
      }
    }
  }
}

但出现错误

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Failed to parse value [1] as only [true] or [false] are allowed."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Failed to parse value [1] as only [true] or [false] are allowed."
  },
  "status": 400
}

它有什么问题?这个映射应该是什么样子?

【问题讨论】:

    标签: elasticsearch elasticsearch-mapping


    【解决方案1】:

    您的请求格式不正确,您将1 传递给preserve_original 参数,该参数仅接受truefalse,如异常中所述。

    除此之外,还有其他一些问题,例如您使用的 String 数据类型在 v7.1 中已被弃用,emails 在您的 JSON 中出现在 properties 之前。

    在我当地测试的正确映射会喜欢

    {
        "settings": {
            "analysis": {
                "filter": {
                    "email": {
                        "type": "pattern_capture",
                        "preserve_original": true,
                        "patterns": [
                            "([^@]+)",
                            "(\\p{L}+)",
                            "(\\d+)",
                            "@(.+)",
                            "([^-@]+)"
                        ]
                    }
                },
                "analyzer": {
                    "email": {
                        "tokenizer": "uax_url_email",
                        "filter": [
                            "email",
                            "lowercase",
                            "unique"
                        ]
                    }
                }
            }
        },
        "mappings": {
            "properties": {
                "email": {
                    "type": "text",
                    "analyzer": "email"
                }
            }
        }
    }
    

    【讨论】:

    • @sadhana,请点击我答案前面的向右箭头来投票并接受答案:)
    【解决方案2】:

    谢谢。

    我插入了几封电子邮件以使用此更正后的映射进行索引。

    现在,当我搜索特定电子邮件时,我会得到所有结果。 我只想拥有一张唱片。我该怎么做?

    http://localhost:9200/test/_search?q=email:abc@abc.net
    
    {
      "took": 6,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 4,
          "relation": "eq"
        },
        "max_score": 0.21149008,
        "hits": [
          {
            "_index": "test",
            "_type": "_doc",
            "_id": "0IWQlXcBnPuV0JvQXCHW",
            "_score": 0.21149008,
            "_source": {
              "email": "abc@abc.net"
            }
          },
          {
            "_index": "test",
            "_type": "_doc",
            "_id": "0oWUlXcBnPuV0JvQISFe",
            "_score": 0.21149008,
            "_source": {
              "email": "abc1@abc.net"
            }
          },
          {
            "_index": "test",
            "_type": "_doc",
            "_id": "z4WQlXcBnPuV0JvQNCGn",
            "_score": 0.19982167,
            "_source": {
              "email": "abc2@abc.net"
            }
          },
          {
            "_index": "test",
            "_type": "_doc",
            "_id": "0YWQlXcBnPuV0JvQdiHo",
            "_score": 0.19982167,
            "_source": {
              "email": "abc3@abc.net"
            }
          }
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      相关资源
      最近更新 更多