Skip to content

Instantly share code, notes, and snippets.

@shairontoledo
Created May 10, 2012 17:32
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 shairontoledo/2654604 to your computer and use it in GitHub Desktop.
Save shairontoledo/2654604 to your computer and use it in GitHub Desktop.
export SERVER=localhost
curl -XPUT --silent "http://$SERVER:9200/documents" -d '
{
"settings" : {
"index" : {
"analysis": {
"analyzer": {
"en": {
"tokenizer": "pattern",
"filter": [
"stop","asciifolding", "standard", "word_delimiter", "lowercase"
]
}
}
}
}
},
"mapping": {
"document":{
"_analyzer": {
"path": "lang_id"
},
"properties" : {
"lang_id" : {
"type" : "string",
"store" : "yes",
"index" : "not_analyzed"
},
"name" : {
"type" : "string",
"store" : "yes",
"index" : "analyzed",
"term_vector" : "with_positions_offsets"
},
"content" : {
"type" : "string",
"store" : "yes",
"index" : "analyzed",
"term_vector" : "with_positions_offsets"
}
}
}
}
}
'
curl -XPUT --silent "http://$SERVER:9200/documents/document/1?pretty=true" -d '
{
"name": "The Scala Collections API.pdf",
"content": "foo bar baz quux",
"lang_id": "en"
}
'
curl -XPUT --silent "http://$SERVER:9200/documents/document/2?pretty=true" -d '
{
"name": "Abstract Members.pdf",
"content": "foo bar baz quux",
"lang_id": "en"
}
'
#Success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true&q=name:scala"
#No Success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true&q=name:pdf"
#No Success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true&q=name:pdf&analyzer=en"
#Success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true" -d '
{
"query":{
"query_string":{
"fields": ["name^7","content"],
"query": "scala",
"analyzer": "en"
}
}
}
'
#Success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true" -d '
{
"query":{
"query_string":{
"fields": ["name^7","content"],
"query": "scala",
"analyzer": "en"
}
}
}
'
#No success
curl -XGET --silent "http://$SERVER:9200/documents/document/_search?pretty=true&analyzer=en" -d '
{
"highlight": {
"number_of_fragments": 3,
"fragment_size": 150,
"fields": {
"name": {},
"content": {}
}
},
"query":{
"query_string":{
"fields": ["name^7","content"],
"query": "pdf",
"analyzer": "en"
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment