【问题标题】:Custom Analyzer not working Elasticsearch自定义分析器不工作 Elasticsearch
【发布时间】:2015-06-08 17:36:48
【问题描述】:
{
  "_source": {
    "enabled": false
  },
  "analysis": {
    "analyzer": {
      "default": {
        "type": "custom",
        "tokenizer": "uax_url_email",
        "filter": "lowercase,standard,stop"
      }
    }
  },
  "mappings": {
    "table": {
      "properties": {
        "field1": {
          "type": "string",
          "include_in_all": false,
          "index": "no"
        },
        "field2": {
          "type": "long",
          "include_in_all": false,
          "index": "no"
        },
        "field3": {
              "type": "string",
              "index": "analyzed"
            }
      }
    }
  }
}

分析器在测试时似乎不工作。分析器不应该索引停用词,它还应该索引整个电子邮件地址。当我“TEST ANALYZER”并输入“Jack is fine”时,所有三个单词的索引都会发生。我不希望它索引英语中的停用词,例如“and”、“is”等。

【问题讨论】:

    标签: elasticsearch elasticsearch-plugin


    【解决方案1】:

    您将字段设置为“索引”:“否”并禁用include_in_all。您如何期望将某些内容放入索引中?引用自documentation

    no 表示它根本不可搜索(作为单独的字段;它可能仍包含在 _all 中)。设置为 no 会禁用 include_in_all

    实际的settings 应该是这样的(您的索引定义中缺少"settings"):

    {
      "_source": {
        "enabled": false
      },
      "settings": {
        "analysis": {
          "analyzer": {
            "default": {
              "type": "custom",
              "tokenizer": "uax_url_email",
              "filter": "lowercase,standard,stop"
            }
          }
        }
      },
      "mappings": {
        "table": {
          "properties": {
            "field1": {
              "type": "string",
              "include_in_all": false,
              "index": "no"
            },
            "field2": {
              "type": "long",
              "include_in_all": false,
              "index": "no"
            },
            "field3": {
              "type": "string",
              "index": "analyzed"
            }
          }
        }
      }
    }
    

    【讨论】:

    • 我确实有其他字段的索引设置为“是”,只是我没有在这个特定的代码 sn-p 中显示这些字段。如果你愿意,我可以给你看。
    • 分享的不止这些,因为问题不完全清楚。分享您尝试过的内容(确切的命令)、结果和期望。
    • 我是stackoverflow的新手,所以不知道要解释多少。我已经进一步解释了这个问题。
    • 我已经编辑了我的答案。您在索引定义中缺少一个关键元素:settings。试试我的代码,看看它是否适合你。
    猜你喜欢
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多