-
-
Save fxh/3246df167e4d72b0372f to your computer and use it in GitHub Desktop.
Failing highlighting example
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
# Elasticsearch highlighting test for ES v1.3.4 | |
curl -XDELETE localhost:9200/hl_test | |
curl -XPUT localhost:9200/hl_test | |
curl -XPOST localhost:9200/hl_test/_close | |
# applying the settings | |
curl -XPUT localhost:9200/hl_test/_settings -d ' | |
{ | |
"index": { | |
"analysis": { | |
"filter": { | |
"en_stem_filter": { | |
"type": "stemmer", | |
"name": "minimal_english" | |
} | |
}, | |
"analyzer": { | |
"en_analyzer": { | |
"alias": ["en"], | |
"type": "custom", | |
"tokenizer": "icu_tokenizer", | |
"filter": ["lowercase", "icu_normalizer", "en_stem_filter", "icu_folding"] | |
}, | |
"my_default": { | |
"alias": ["standard"], | |
"type": "custom", | |
"tokenizer": "icu_tokenizer", | |
"filter": ["icu_folding", "icu_normalizer"] | |
} | |
} | |
} | |
} | |
}' | |
curl -XPOST localhost:9200/hl_test/_open | |
# applying the mapping | |
curl -XPUT localhost:9200/hl_test/item/_mapping -d ' | |
{ | |
"_analyzer": { | |
"path": "language_code" | |
}, | |
"properties": { | |
"language_code": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"title": { | |
"type": "string", | |
"analyzer": "my_default", | |
"fields": { | |
"stemmed": { | |
"type": "string", | |
"term_vector": "with_positions_offsets", | |
"include_in_all": false | |
} | |
} | |
} | |
} | |
}' | |
curl -XPUT localhost:9200/hl_test/item/1 -d '{ | |
"language_code": "en", | |
"title": "And some analysis tests." | |
}' | |
curl -XPOST localhost:9200/hl_test/_flush | |
### | |
# highlighting example that is not working: | |
### | |
curl -XGET localhost:9200/hl_test/item/_search?pretty -d '{ | |
"query": { | |
"match": { | |
"title": { | |
"query": "analysis", | |
"analyzer": "my_default" | |
} | |
} | |
}, | |
"highlight": { | |
"fields": { | |
"title": {"type": "plain", "number_of_fragments": 0} | |
} | |
} | |
}' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.15342641, | |
"hits" : [ { | |
"_index" : "hl_test", | |
"_type" : "item", | |
"_id" : "1", | |
"_score" : 0.15342641, | |
"_source":{ | |
"language_code": "en", | |
"title": "And some analysis tests." | |
} | |
} ] | |
} | |
} | |
### | |
# however if I query for something that is not adjusted by the stemmer, it works: | |
### | |
curl -XGET localhost:9200/hl_test/item/_search?pretty -d '{ | |
"query": { | |
"match": { | |
"title": { | |
"query": "some", | |
"analyzer": "my_default" | |
} | |
} | |
}, | |
"highlight": { | |
"fields": { | |
"title": {"type": "plain", "number_of_fragments": 0} | |
} | |
} | |
}' | |
{ | |
"took" : 2, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.15342641, | |
"hits" : [ { | |
"_index" : "hl_test", | |
"_type" : "item", | |
"_id" : "1", | |
"_score" : 0.15342641, | |
"_source":{ | |
"language_code": "en", | |
"title": "And some analysis tests." | |
}, | |
"highlight" : { | |
"title" : [ "And <em>some</em> analysis tests." ] | |
} | |
} ] | |
} | |
} | |
### | |
# and on the stemmed field it works too | |
### | |
curl -XGET localhost:9200/hl_test/item/_search?pretty -d '{ | |
"query": { | |
"match": { | |
"title.stemmed": { | |
"query": "analysis", | |
"analyzer": "en" | |
} | |
} | |
}, | |
"highlight": { | |
"fields": { | |
"title.stemmed": {"type": "plain", "number_of_fragments": 0} | |
} | |
} | |
}' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.15342641, | |
"hits" : [ { | |
"_index" : "hl_test", | |
"_type" : "item", | |
"_id" : "1", | |
"_score" : 0.15342641, | |
"_source":{ | |
"language_code": "en", | |
"title": "And some analysis tests." | |
}, | |
"highlight" : { | |
"title.stemmed" : [ "And some <em>analysis</em> tests." ] | |
} | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment