Created
October 16, 2012 15:23
-
-
Save wires/3899939 to your computer and use it in GitHub Desktop.
Elastic search strange highlighting behaviour
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
export ES='http://localhost:9200' | |
# avoid colorizing when using less | |
if [ -t 1 ]; then | |
alias pp='python -mjson.tool | pygmentize -l javascript' | |
else | |
alias pp='python -mjson.tool' | |
fi | |
curl -s -XDELETE $ES/highlightdebug > /dev/null | |
curl -s -XPUT $ES/highlightdebug -d'{ | |
"index": { | |
"number_of_shards": 1, | |
"number_of_replicas": 0 | |
} | |
}' > /dev/null | |
curl -s -XPUT $ES/highlightdebug/testdocs/1 -d'{ "title":"cheese" }' > /dev/null | |
curl -s -XPOST $ES/highlightdebug/_refresh > /dev/null | |
# uncomment the following to see which commands are executed | |
echo "\n\ndoes highlight:" | |
curl -s $ES/highlightdebug/_search -d'{ | |
"query": { | |
"bool": { | |
"must": [{ | |
"constant_score": { | |
"query": { | |
"term": { "title": "cheese" } | |
}, | |
"boost": 1.0 | |
} | |
}] | |
} | |
}, | |
"highlight": { | |
"fields": { "title": {} } | |
} | |
}' |pp | |
echo "\n\ndoesn't highlight:" | |
curl -s $ES/highlightdebug/_search -d'{ | |
"query": { | |
"bool": { | |
"should": [{ | |
"constant_score": { | |
"query": { | |
"term": { "title": "cheese" } | |
}, | |
"boost": 1.0 | |
} | |
}] | |
} | |
}, | |
"highlight": { | |
"fields": { "title": {} } | |
} | |
}' |pp | |
echo "\n\ndoes highlight" | |
curl -s $ES/highlightdebug/_search -d'{ | |
"query": { | |
"bool": { | |
"should": [{ | |
"term": { "title": "cheese" } | |
}] | |
} | |
}, | |
"highlight": { | |
"fields": { "title": {} } | |
} | |
}' |pp | |
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
does highlight: | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "1", | |
"_index": "highlightdebug", | |
"_score": 1.0, | |
"_source": { | |
"title": "cheese" | |
}, | |
"_type": "testdocs", | |
"highlight": { | |
"title": [ | |
"<em>cheese</em>" | |
] | |
} | |
} | |
], | |
"max_score": 1.0, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 2 | |
} | |
doesn't highlight: | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "1", | |
"_index": "highlightdebug", | |
"_score": 1.0, | |
"_source": { | |
"title": "cheese" | |
}, | |
"_type": "testdocs" | |
} | |
], | |
"max_score": 1.0, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 1 | |
} | |
does highlight | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "1", | |
"_index": "highlightdebug", | |
"_score": 0.30685282, | |
"_source": { | |
"title": "cheese" | |
}, | |
"_type": "testdocs", | |
"highlight": { | |
"title": [ | |
"<em>cheese</em>" | |
] | |
} | |
} | |
], | |
"max_score": 0.30685282, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment