Skip to content

Instantly share code, notes, and snippets.

@joren
Last active December 20, 2015 11:00
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 joren/6120272 to your computer and use it in GitHub Desktop.
Save joren/6120272 to your computer and use it in GitHub Desktop.
Elasticsearch problem
settings analysis: {
filter: {
myNgram: {
type: 'nGram',
max_gram: 12,
min_gram: 3
}
},
analyzer: {
name_analyzer: {
tokenizer: 'standard',
filter: %w[lowercase myNgram],
type: 'custom'
},
}
}
~ curl -XGET 'localhost:9200/_analyze?analyzer=name_analyzer&index=clients' -d 'jm brun' ruby-2.0.0
{"tokens":[{"token":"bru","start_offset":3,"end_offset":6,"type":"word","position":1},{"token":"run","start_offset":4,"end_offset":7,"type":"word","position":2},{"token":"brun","start_offset":3,"end_offset":7,"type":"word","position":3}]}%
~ curl -XGET 'localhost:9200/_analyze?analyzer=name_analyzer&index=clients' -d 'jore' ruby-2.0.0
{"tokens":[{"token":"jor","start_offset":0,"end_offset":3,"type":"word","position":1},{"token":"ore","start_offset":1,"end_offset":4,"type":"word","position":2},{"token":"jore","start_offset":0,"end_offset":4,"type":"word","position":3}]}%
~ curl -X GET 'http://localhost:9200/clients/client/_search?load=true&size=4&pretty' -d '{"query":{"query_string":{"query":"name:jore"}},"size":4}' ruby-2.0.0
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 12,
"max_score" : 2.2767696,
"hits" : [ {
"_index" : "clients",
"_type" : "client",
"_id" : "273",
"_score" : 2.2767696, "_source" : {"name":"Joren De Groof","shortname":"joren"}
}, {
"_index" : "clients",
"_type" : "client",
"_id" : "1070",
"_score" : 1.1383848, "_source" : {"name":"jorendegroof","shortname":"jorendegroof"}
} ]
}
}%
~ curl -X GET 'http://localhost:9200/clients/client/_search?load=true&size=4&pretty' -d '{"query":{"query_string":{"query":"jore"}},"size":4}' ruby-2.0.0
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}%
~ curl -X GET 'http://localhost:9200/clients/client/_search?load=true&size=4&pretty' -d '{"query":{"query_string":{"query":"name:jm brun"}},"size":4}' ruby-2.0.0
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}%
~ curl -X GET 'http://localhost:9200/clients/client/_search?load=true&size=4&pretty' -d '{"query":{"query_string":{"query":"jm brun"}},"size":4}' ruby-2.0.0
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.6683317,
"hits" : [ {
"_index" : "clients",
"_type" : "client",
"_id" : "65",
"_score" : 0.6683317, "_source" : {"name":"JM Bruneau","shortname":"jm_bruneau"}
} ]
}
}%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment