自定义分析器不工作Elasticsearch

时间:2015-06-08 06:46:58

标签: elasticsearch elasticsearch-plugin

{
  "_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”时,会对所有三个单词进行索引。我不希望它用英语中的停用词编制索引,例如“和”,“是”等等。

1 个答案:

答案 0 :(得分:0)

您将字段设置为" index":" no"并禁用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"
        }
      }
    }
  }
}