Skip to content

Instantly share code, notes, and snippets.

@imotov
Forked from nekulin/ElasticSearch Highlighting
Last active December 16, 2015 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/5488014 to your computer and use it in GitHub Desktop.
Save imotov/5488014 to your computer and use it in GitHub Desktop.
curl -XDELETE "http://localhost:9200/test/"
curl -XPUT "http://localhost:9200/test/" -d '{
"mappings": {
"product": {
"properties": {
"doc": {
"properties": {
"name": {
"type": "string",
"include_in_all": true
}
}
}
}
}
}
}
'
# Insert
curl -XPUT "http://localhost:9200/test/product/1" -d '{ "doc":{"name":"Горчица"} }'
curl -XPUT "http://localhost:9200/test/product/2" -d '{ "doc":{"name":"Молоко"} }'
curl -XPUT "http://localhost:9200/test/product/3" -d '{ "doc":{"name":"Кефир жирный 2"} }'
curl -XPUT "http://localhost:9200/test/product/4" -d '{ "doc":{"name":"Кефир жирный"} }'
curl -XPUT "http://localhost:9200/test/product/5" -d '{ "doc":{"name":"Виски"} }'
curl -XPOST "http://localhost:9200/test/_refresh"
# Search highlight
curl -XPOST "http://localhost:9200/test/product/_search?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>"
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment