Skip to content

Instantly share code, notes, and snippets.

@nekulin
Created April 30, 2013 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nekulin/5486789 to your computer and use it in GitHub Desktop.
Save nekulin/5486789 to your computer and use it in GitHub Desktop.
ElasticSearch Highlighting
Mapping
{
"product" : {
"properties" : {
"doc" : {
"properties" : {
"name" : {
"type" : "string",
"include_in_all" : true
}
}
}
}
}
}
// Insert
curl -XPOST "http://localhost:9200/test/product/1" -d '{ "doc":{"name":"Горчица"} }'
curl -XPOST "http://localhost:9200/test/product/2" -d '{ "doc":{"name":"Молоко"} }'
curl -XPOST "http://localhost:9200/test/product/3" -d '{ "doc":{"name":"Кефир жирный 2"} }'
curl -XPOST "http://localhost:9200/test/product/4" -d '{ "doc":{"name":"Кефир жирный"} }'
curl -XPOST "http://localhost:9200/test/product/5" -d '{ "doc":{"name":"Виски"} }'
// Search highlight
curl -XPOST "http://localhost:9200/test/product?pretty=true" -d '
{
"query": {
"query_string": {
"query": "doc.name:Молоко",
"analyzer": "standard"
}
},
"highlight": {
"number_of_fragments": 0,
"fields": {
"doc.name": {}
},
"pre_tags": "<b>",
"post_tags": "</b>"
}
}
'
Найденое молоко не выделилось тегами <b></b>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment