Skip to content

Instantly share code, notes, and snippets.

@jprante
Created November 19, 2013 19:34
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 jprante/7551124 to your computer and use it in GitHub Desktop.
Save jprante/7551124 to your computer and use it in GitHub Desktop.
An example of broader/narrower SKOS for Elasticsearch SKOS plugin
curl -XDELETE 'localhost:9200/test'
curl -XPOST 'http://localhost:9200/test' -d '{
"settings" : {
"index" : {
"analysis" : {
"filter": {
"skosfilter" : {
"type": "skos",
"path": "/var/tmp/indexpath/",
"skosFile": "ukat_examples.n3",
"expansionType": "LABEL",
"skosType": "PREF ALT BROADER NARROWER"
}
},
"analyzer" : {
"skos" : {
"type" : "custom",
"tokenizer" : "keyword",
"filter" : "skosfilter"
}
}
}
}
},
"mappings" : {
"_default_" : {
"properties" : {
"subject" : {
"type" : "string",
"store" : true,
"index_analyzer" : "skos",
"search_analyzer" : "standard"
}
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/subjects/1' -d '{
"title" : "Spearhead",
"description": "Roman iron spearhead. The spearhead was attached to one end of a wooden shaft.The spear was mainly a thrusting weapon, but could also be thrown. It was the principal weapon of the auxiliary soldier. (second - fourth century, Arbeia Roman Fort)",
"subject" : "Weapons"
}'
curl -XPUT 'http://localhost:9200/test/subjects/2' -d '{
"title" : "Vitruvius Ballista",
"description": "This ballista is a palintone or stone throwing machine. Bestia represents the smallest stone thrower in the Roman army. It is a 2 libra (2 pounder). The stones would not be capable of knocking down walls, but would be ideal if used against groups of warriors or being dropped into hill forts or towns.",
"subject" : "Arms"
}'
curl -XPOST 'http://localhost:9200/test/_refresh'
# should give two hits
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"match" : {
"subject": "Arms"
}
}
}'
# should give two hits
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"match" : {
"subject": "Weapons"
}
}
}'
# should give no hit
curl -XGET 'http://localhost:9200/test/_search?pretty' -d '{
"query": {
"match" : {
"subject": "foo bar"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment