Custom Analyzer not working Elasticsearch

869 views Asked by At
{
  "_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"
            }
      }
    }
  }
}

The analyzer doesn't seem to work when testing it. The analyzer should not index stop words and it should also index an email address as a whole. When I "TEST ANALYZER" and type "Jack is fine", indexing of all three words takes place. I do not want it to index the stopwords in english language such as "and","is" etc.

1

There are 1 answers

4
Andrei Stefan On BEST ANSWER

You set the fields to be "index": "no" and also disable include_in_all. How do you expect to have something put in the index? Quote from the documentation:

no means that it won’t be searchable at all (as an individual field; it may still be included in _all). Setting to no disables include_in_all.

And the actual settings should be like this (you are missing "settings" from your index definition):

{
  "_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"
        }
      }
    }
  }
}