Skip to content

Instantly share code, notes, and snippets.

@clintongormley
Created June 21, 2011 10:06
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save clintongormley/1037563 to your computer and use it in GitHub Desktop.
Save clintongormley/1037563 to your computer and use it in GitHub Desktop.
Edge ngram example for elasticsearch
# [Tue Jun 21 12:05:39 2011] Protocol: http, Server: 192.168.5.103:9200
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"mappings" : {
"contact" : {
"properties" : {
"twitter" : {
"type" : "object",
"properties" : {
"profile" : {
"fields" : {
"profile" : {
"type" : "string",
"analyzer" : "left"
},
"reverse_profile" : {
"type" : "string",
"analyzer" : "right"
}
},
"type" : "multi_field"
}
}
}
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"left" : {
"filter" : [
"standard",
"lowercase",
"stop"
],
"type" : "custom",
"tokenizer" : "left_tokenizer"
},
"right" : {
"filter" : [
"standard",
"lowercase",
"stop"
],
"type" : "custom",
"tokenizer" : "right_tokenizer"
}
},
"tokenizer" : {
"left_tokenizer" : {
"side" : "front",
"max_gram" : 20,
"type" : "edgeNGram"
},
"right_tokenizer" : {
"side" : "back",
"max_gram" : 20,
"type" : "edgeNGram"
}
}
}
}
}
'
# [Tue Jun 21 12:05:39 2011] Response:
# {
# "ok" : true,
# "acknowledged" : true
# }
# [Tue Jun 21 12:05:44 2011] Protocol: http, Server: 192.168.5.103:9200
curl -XPOST 'http://127.0.0.1:9200/test/contact?pretty=1' -d '
{
"twitter" : {
"profile" : "alexander smith"
}
}
'
# [Tue Jun 21 12:05:44 2011] Response:
# {
# "ok" : true,
# "_index" : "test",
# "_id" : "qvpprlH9Rg-znLPfi0JUdA",
# "_type" : "contact",
# "_version" : 1
# }
# [Tue Jun 21 12:05:47 2011] Protocol: http, Server: 192.168.5.103:9200
curl -XPOST 'http://127.0.0.1:9200/test/contact?pretty=1' -d '
{
"twitter" : {
"profile" : "ben alexander"
}
}
'
# [Tue Jun 21 12:05:47 2011] Response:
# {
# "ok" : true,
# "_index" : "test",
# "_id" : "R5_r5kYhTwarSV92DY_9Fg",
# "_type" : "contact",
# "_version" : 1
# }
# [Tue Jun 21 12:05:50 2011] Protocol: http, Server: 192.168.5.103:9200
curl -XGET 'http://127.0.0.1:9200/test/contact/_search?pretty=1' -d '
{
"query" : {
"query_string" : {
"fields" : [
"twitter.profile",
"twitter.profile.reverse_profile"
],
"query" : "alexander"
}
}
}
'
# [Tue Jun 21 12:05:50 2011] Response:
# {
# "hits" : {
# "hits" : [
# {
# "_source" : {
# "twitter" : {
# "profile" : "ben alexander"
# }
# },
# "_score" : 0.07490276,
# "_index" : "test",
# "_id" : "R5_r5kYhTwarSV92DY_9Fg",
# "_type" : "contact"
# },
# {
# "_source" : {
# "twitter" : {
# "profile" : "alexander smith"
# }
# },
# "_score" : 0.062772445,
# "_index" : "test",
# "_id" : "qvpprlH9Rg-znLPfi0JUdA",
# "_type" : "contact"
# }
# ],
# "max_score" : 0.07490276,
# "total" : 2
# },
# "timed_out" : false,
# "_shards" : {
# "failed" : 0,
# "successful" : 5,
# "total" : 5
# },
# "took" : 6
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment