Skip to content

Instantly share code, notes, and snippets.

@nik9000
Created September 20, 2013 15:02
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 nik9000/6638883 to your computer and use it in GitHub Desktop.
Save nik9000/6638883 to your computer and use it in GitHub Desktop.
Highlighting subfields
#!/bin/bash
curl -XDELETE "http://localhost:9200/test?pretty" -s
curl -XPOST "http://localhost:9200/test?pretty" -s
curl -XPUT http://localhost:9200/test/test/_mapping?pretty -d'{
"test" : {
"properties": {
"foo" : {
"type": "multi_field",
"fields": {
"foo": {
"type": "string",
"analyzer": "english",
"store": "yes",
"term_vector" : "with_positions_offsets"
},
"plain": {
"type": "string",
"analyzer": "standard",
"store": "yes",
"term_vector" : "with_positions_offsets"
}
}
}
}
}
}'
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true&wait_for_status=yellow'
curl -XPOST "http://localhost:9200/test/test?pretty" -d '{"foo": "run with scissors"}'
curl -XPOST "http://localhost:9200/test/test?pretty" -d '{"foo": "running with scissors"}'
curl -XPOST "http://localhost:9200/test/_refresh?pretty" -s
curl -XPOST "http://localhost:9200/test/test/_search?pretty" -d '{
"query": {
"query_string": {
"query": "foo.plain:running scissors",
"fields": ["foo"],
"default_operator": "AND"
}
},
"highlight": {
"order": "score",
"fields": {
"foo": {
"number_of_fragments": 1
},
"foo.plain": {
"number_of_fragments": 1
}
}
}
}'
# {
# "took" : 8,
# "timed_out" : false,
# "_shards" : {
# "total" : 5,
# "successful" : 5,
# "failed" : 0
# },
# "hits" : {
# "total" : 1,
# "max_score" : 0.2712221,
# "hits" : [ {
# "_index" : "test",
# "_type" : "test",
# "_id" : "0yZSkBB_TEekc-RA_qBNJg",
# "_score" : 0.2712221, "_source" : {"foo": "running with scissors"},
# "highlight" : {
# "foo.plain" : [ "<em>running</em> with scissors" ],
# "foo" : [ "running with <em>scissors</em>" ]
# }
# } ]
# }
# }
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment