Mark
Mark

Reputation: 70010

"stop" filter behaving differently in Elasticsearch when using "_all"

I'm trying to implement a match search in Elasticsearch, and I noticed that the behavior is different depending if I use _all or if a enter a specific string value as the field name of my query.

To give some context, I've created an index with the following settings:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "default": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "stop",
            "kstem",
            "word_delimiter"
          ]
        }
      }
    }
  }
}

If I create a document like:

{
  "name": "Hello.World"
}

And I execute a search using _all like:

 curl -d '{"query": { "match" : { "_all" : "hello" } }}' http://localhost:9200/myindex/mytype/_search

It will correctly match the document (since I'm using the stop filter to split the words at the dot), but if I execute this query instead:

curl -d '{"query": { "match" : { "name" : "hello" } }}' http://localhost:9200/myindex/mytype/_search

Nothing is being returned instead. How is this possible?

Upvotes: 0

Views: 55

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

Issue a GET for /myindex/mytype/_mapping and see if your index is configured the way you think it is. Meaning, see if that "name" field is not_analyzed, for example.

Even more, run the following query to see how name field is actually indexed:

{
  "query": {
    "match": {
      "name": "hello"
    }
  },
  "fielddata_fields": ["name"]
}

You should see something like this in the result:

    "fields": {
       "name": [
          "hello",
          "world"
       ]
    }

If you don't, then you know something's wrong with your mapping for the name field.

Upvotes: 1

Related Questions