Created
October 9, 2019 14:14
-
-
Save bdelbosc/8ef2f6edcde641826096ae8096849b63 to your computer and use it in GitHub Desktop.
Elasticsearch match_phrase_prefix change between 6.6.2 and 6.7.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start Elasticsearch 6.6.2 | |
docker run -p 9200:9200 docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.2 | |
# 1. Create an index with a mapping | |
curl -X PUT "http://localhost:9200/my-index?pretty" -H 'Content-Type: application/json' -d'{ | |
"settings": { | |
"index": { | |
"number_of_shards": 1, | |
"number_of_replicas": 0 | |
} | |
}, | |
"mappings": { | |
"_doc": { | |
"properties": { | |
"title": { | |
"type": "keyword", | |
"fields": { | |
"fulltext": { | |
"type": "text" | |
} | |
}, | |
"ignore_above": 255 | |
} | |
} | |
} | |
} | |
}' | |
# Response | |
{ | |
"acknowledged" : true, | |
"shards_acknowledged" : true, | |
"index" : "my-index" | |
} | |
# ------------------ | |
# 2. Create a document | |
# | |
curl -X PUT "http://localhost:9200/my-index/_doc/1" -H 'Content-Type: application/json' -d '{ "title": "UPPER CASE TITLE" }' | |
# Response | |
{"_index":"my-index","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":1,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1} | |
# ------------------ | |
# 3. Search | |
curl -XGET 'http://localhost:9200/my-index/_doc/_search?pretty' -H 'Content-Type: application/json' -d '{"from":0,"size":10,"query":{"match_phrase_prefix":{"title":{"query":"UPPER","slop":0,"max_expansions":50,"boost":1.0}}},"_source":{"includes":["_id"],"excludes":[]}}' | |
# Response in 6.6.2 -> No hit | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 0, | |
"max_score" : null, | |
"hits" : [ ] | |
} | |
} | |
# Now stop elasticsearch and start a 6.7.0 | |
docker run -p 9200:9200 docker.elastic.co/elasticsearch/elasticsearch-oss:6.7.0 | |
# Play command 1, 2 and 3, the search result contains a hit | |
{ | |
"took" : 90, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.2876821, | |
"hits" : [ | |
{ | |
"_index" : "my-index", | |
"_type" : "_doc", | |
"_id" : "1", | |
"_score" : 0.2876821, | |
"_source" : { } | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment