Skip to content

Instantly share code, notes, and snippets.

@hukl
Forked from clintongormley/gist:961303
Created May 8, 2011 11:10
Show Gist options
  • Save hukl/961310 to your computer and use it in GitHub Desktop.
Save hukl/961310 to your computer and use it in GitHub Desktop.
Ngram example
###################
# CREATE THE INDEX:
###################
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"settings" : {
"analysis" : {
"filter" : {
"edge_ngram" : {
"side" : "front",
"max_gram" : 20,
"min_gram" : 1,
"type" : "edgeNGram"
}
},
"analyzer" : {
"ascii_ngram" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"nGram"
],
"type" : "custom",
"tokenizer" : "standard"
},
"ascii_std" : {
"filter" : [
"standard",
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "standard"
},
"ascii_edge_ngram" : {
"filter" : [
"standard",
"lowercase",
"asciifolding",
"edge_ngram"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}
'
# [Sun May 8 12:56:59 2011] Response:
# {
# "ok" : true,
# "acknowledged" : true
# }
###################
# PUT THE MAPPING
###################
curl -XPUT 'http://127.0.0.1:9200/test/website/_mapping?pretty=1' -d '
{
"website" : {
"properties" : {
"title" : {
"search_analyzer" : "ascii_std",
"index_analyzer" : "ascii_edge_ngram",
"type" : "string"
},
"description" : {
"search_analyzer" : "ascii_std",
"index_analyzer" : "ascii_edge_ngram",
"type" : "string"
},
"tags" : {
"search_analyzer" : "ascii_std",
"index_analyzer" : "ascii_edge_ngram",
"type" : "string"
},
"uri" : {
"type" : "string",
"include_in_all" : 0,
"analyzer" : "ascii_ngram"
}
}
}
}
'
# [Sun May 8 12:58:16 2011] Response:
# {
# "ok" : true,
# "acknowledged" : true
# }
###################
# INDEX A DOC
###################
curl -XPOST 'http://127.0.0.1:9200/test/website?pretty=1' -d '
{
"title" : "a german news site",
"description" : "very helpful",
"tags" : [
"news",
"german"
],
"uri" : "http://www.heise.de"
}
'
# [Sun May 8 12:58:52 2011] Response:
# {
# "ok" : true,
# "_index" : "test",
# "_id" : "veqYjNIiRI2KT5nQGNSRIQ",
# "_type" : "website",
# "_version" : 1
# }
###################
# SEARCH FOR 'ger'
###################
curl -XGET 'http://127.0.0.1:9200/test/website/_search?pretty=1' -d '
{
"query" : {
"dis_max" : {
"queries" : [
{
"field" : {
"uri" : "ger"
}
},
{
"field" : {
"_all" : "ger"
}
}
]
}
}
}
'
# [Sun May 8 12:59:07 2011] Response:
# {
# "hits" : {
# "hits" : [
# {
# "_source" : {
# "title" : "a german news site",
# "description" : "very helpful",
# "uri" : "http://www.heise.de",
# "tags" : [
# "news",
# "german"
# ]
# },
# "_score" : 0.0025187703,
# "_index" : "test",
# "_id" : "veqYjNIiRI2KT5nQGNSRIQ",
# "_type" : "website"
# }
# ],
# "max_score" : 0.0025187703,
# "total" : 1
# },
# "timed_out" : false,
# "_shards" : {
# "failed" : 0,
# "successful" : 5,
# "total" : 5
# },
# "took" : 2
# }
###################
# SEARCH FOR 'eis'
###################
curl -XGET 'http://127.0.0.1:9200/test/website/_search?pretty=1' -d '
{
"query" : {
"dis_max" : {
"queries" : [
{
"field" : {
"uri" : "eis"
}
},
{
"field" : {
"_all" : "eis"
}
}
]
}
}
}
'
# [Sun May 8 12:59:57 2011] Response:
# {
# "hits" : {
# "hits" : [
# {
# "_source" : {
# "title" : "a german news site",
# "description" : "very helpful",
# "uri" : "http://www.heise.de",
# "tags" : [
# "news",
# "german"
# ]
# },
# "_score" : 0.08433159,
# "_index" : "test",
# "_id" : "veqYjNIiRI2KT5nQGNSRIQ",
# "_type" : "website"
# }
# ],
# "max_score" : 0.08433159,
# "total" : 1
# },
# "timed_out" : false,
# "_shards" : {
# "failed" : 0,
# "successful" : 5,
# "total" : 5
# },
# "took" : 4
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment