elasticsearch/elasticsearch — Issue #1547: 0.18.5 ignores query string analyzer
Author: erickt
Created: 2011-12-16 21:38:02+00:00
State: open

This script shows a regression between 0.17.8 and 0.18.5's query string searching:

#!/bin/sh

set -e

URL="http://localhost:9200"

function run() {
echo "%" "$@"
"$@"
echo
echo
}

run curl -XDELETE "$URL/test/"
run curl -XDELETE "$URL/_percolator"
run curl -XPUT "$URL/test/" -d '
{
"index": {},
"settings": {
"analysis": {
"analyzer": {
"dash_path": { "type": "custom", "tokenizer": "dash_path" }
},
"tokenizer": {
"dash_path": { "type": "path_hierarchy", "delimiter": "-" }
}
}
},
"mappings": {
"test": {
"properties": {
"location": { "type":"string", "analyzer": "dash_path" }
}
}
}
}'
run curl -XGET "$URL/test/_mapping"
run curl -XGET "$URL/test/_analyze?field=test.location&pretty=true" -d "A-A-A"

run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"A-A-A"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"A-A-B"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"A-B-A"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"A-B-B"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"B-A-A"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"B-A-B"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"B-B-A"}'
run curl -XPOST "$URL/test/test/?refresh=true" -d '{"location":"B-B-B"}'
run curl -XGET "$URL/test/test/_search?pretty=true" -d '
{
"query": {
"query_string": {
"query": "location:A-B",
"analyzer": "keyword"
}
}
}'

In 0.17.8, it returns the proper values:

{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test",
"_type" : "test",
"_id" : "Z2PnXuc9TbmPiLwdh9sOjA",
"_score" : 1.0, "_source" : {"location":"A-B-A"}
}, {
"_index" : "test",
"_type" : "test",
"_id" : "RK20FlyfQBq29K503MiZSQ",
"_score" : 1.0, "_source" : {"location":"A-B-B"}
} ]
}
}

But in 0.18.5, it returns this (It should only include things with the prefix `A-B`):

{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 1.4142135,
"hits" : [ {
"_index" : "test",
"_type" : "test",
"_id" : "sHEIGa73QbmU3V6btCMmFg",
"_score" : 1.4142135, "_source" : {"location":"A-B-B"}
}, {
"_index" : "test",
"_type" : "test",
"_id" : "dxSFQNu_RLCwNU4rQYnB4g",
"_score" : 1.4142135, "_source" : {"location":"A-B-A"}
}, {
"_index" : "test",
"_type" : "test",
"_id" : "VyrcXa3AS3qoJ6ZueL1ufQ",
"_score" : 0.5085423, "_source" : {"location":"A-A-A"}
}, {
"_index" : "test",
"_type" : "test",
"_id" : "AYPtN0ppS7GNcBCKmLfIvw",
"_score" : 0.5085423, "_source" : {"location":"A-A-B"}
} ]
}
}