Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created March 14, 2011 22:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-vlcek/869979 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/869979 to your computer and use it in GitHub Desktop.
Fixed highlight query for alheim
// start a fresh ES node with default setup and index a document
curl -PUT 'http://localhost:9200/devalexbk10/usr/1' -d '{
{
"id":2741,
"title":"John Doe",
"creationDate":"2011-02-23 13:44:14",
"login":"jdoe@localhost.com",
"firstName":"John",
"lastName":"Doe",
"locations":["1864","2","1597","1598"]
}'
// query (based on https://gist.github.com/869446)
curl -XGET 'http://localhost:9200/devalexbk10/usr/_search?pretty=true' -d '
{
"query":{
"filtered":{
"query":{
"query_string":{
"default_field":"title",
"default_operator":"AND",
"query":"John"
}
},
"filter":{
"or":[{"term":{"locations":1}},{"term":{"locations":2}}]
}
}
},
"highlight":{
"fields":{"title":{"fragment_size":150,"number_of_fragments":3}}
}
}'
// result
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.19178301,
"hits" : [ {
"_index" : "devalexbk10",
"_type" : "usr",
"_id" : "1",
"_score" : 0.19178301, "_source" :
{
"id":2741,
"title":"John Doe",
"creationDate":"2011-02-23 13:44:14",
"login":"jdoe@localhost.com",
"firstName":"John",
"lastName":"Doe",
"locations":["1864","2","1597","1598"]
},
"highlight" : {
"title" : [ "<em>John</em> Doe" ]
}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment