Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created February 21, 2013 15:55
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 clintongormley/5005666 to your computer and use it in GitHub Desktop.
Save clintongormley/5005666 to your computer and use it in GitHub Desktop.
curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1' -d '
{
"mappings" : {
"product" : {
"properties" : {
"code" : {
"fields" : {
"ngram" : {
"type" : "string",
"analyzer" : "ngram"
},
"code" : {
"type" : "string"
}
},
"type" : "multi_field"
}
}
}
},
"settings" : {
"analysis" : {
"filter" : {
"ngram" : {
"max_gram" : 20,
"min_gram" : 1,
"type" : "ngram"
}
},
"analyzer" : {
"ngram" : {
"filter" : [
"standard",
"lowercase",
"ngram"
],
"tokenizer" : "standard"
}
}
}
}
}
'
curl -X POST 'localhost:9200/myindex/product' -d '{
"code" : "Samsung Galaxy i7500"
}'
curl -X POST 'localhost:9200/myindex/product' -d '{
"code" : "Samsung Galaxy 5 Europa"
}'
curl -X POST 'localhost:9200/myindex/product' -d '{
"code" : "Samsung Galaxy Mini"
}'
curl -XGET 'http://127.0.0.1:9200/myindex/_search?pretty=1' -d '
{
"query" : {
"query_string" : {
"query" : "sam xy",
"default_field" : "code.ngram",
"analyzer" : "whitespace"
}
},
"highlight" : {
"fields" : {
"code.ngram" : {}
},
"number_of_fragments" : 0
}
}
'
# [Thu Feb 21 16:54:58 2013] Response:
# {
# "hits" : {
# "hits" : [
# {
# "_source" : {
# "code" : "Samsung Galaxy Mini"
# },
# "_score" : 0.054244425,
# "_index" : "myindex",
# "_id" : "AWi5ApmKSaynyI8fMowg4A",
# "_type" : "product",
# "highlight" : {
# "code.ngram" : [
# "Samsun<em>Sam</em>g Galax<em>xy</em> Mini"
# ]
# }
# },
# {
# "_source" : {
# "code" : "Samsung Galaxy i7500"
# },
# "_score" : 0.054244425,
# "_index" : "myindex",
# "_id" : "UW65yFatTBOA_hAQO8prTg",
# "_type" : "product",
# "highlight" : {
# "code.ngram" : [
# "Samsun<em>Sam</em>g Galax<em>xy</em> i7500"
# ]
# }
# },
# {
# "_source" : {
# "code" : "Samsung Galaxy 5 Europa"
# },
# "_score" : 0.04746387,
# "_index" : "myindex",
# "_id" : "zCB25DQYQ_eN6W32z5ysSA",
# "_type" : "product",
# "highlight" : {
# "code.ngram" : [
# "Samsun<em>Sam</em>g Galax<em>xy</em> 5 Europa"
# ]
# }
# }
# ],
# "max_score" : 0.054244425,
# "total" : 3
# },
# "timed_out" : false,
# "_shards" : {
# "failed" : 0,
# "successful" : 5,
# "total" : 5
# },
# "took" : 10
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment