Created
March 5, 2012 16:30
-
-
Save jwyuan/1979125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d ' | |
{ | |
"mappings" : { | |
"member" : { | |
"properties" : { | |
"name" : { | |
"type": "multi_field", | |
"fields" : { | |
"untouched": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"name": { | |
"type": "string", | |
"analyzer": "standard_name" | |
}, | |
"ngram" : { | |
"search_analyzer": "standard_name", | |
"index_analyzer": "partial_name", | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"settings" : { | |
"analysis" : { | |
"filter" : { | |
"name_ngrams" : { | |
"side" : "front", | |
"max_gram" : 10, | |
"min_gram" : 1, | |
"type" : "edgeNGram" | |
} | |
}, | |
"analyzer" : { | |
"standard_name" : { | |
"filter" : [ | |
"standard", | |
"lowercase", | |
"asciifolding" | |
], | |
"type" : "custom", | |
"tokenizer" : "standard" | |
}, | |
"partial_name" : { | |
"filter" : [ | |
"standard", | |
"lowercase", | |
"asciifolding", | |
"name_ngrams" | |
], | |
"type" : "custom", | |
"tokenizer" : "standard" | |
} | |
} | |
} | |
} | |
} | |
' | |
{ | |
"ok" : true, | |
"acknowledged" : true | |
} | |
curl -X POST 'http://localhost:9200/test/test?pretty=true' -d '{ "name" : "The Office" }' | |
{ | |
"ok" : true, | |
"_index" : "test", | |
"_type" : "test", | |
"_id" : "-h5HOUGKSxavy_EPhj5H7w", | |
"_version" : 1 | |
} | |
curl -X POST 'http://localhost:9200/test/test?pretty=true' -d '{ "name" : "The Office (UK)" }' | |
{ | |
"ok" : true, | |
"_index" : "test", | |
"_type" : "test", | |
"_id" : "RJ40-EeDSwW8OHyePF4KRQ", | |
"_version" : 1 | |
} | |
// Why does this have no match? | |
curl -XGET 'http://127.0.0.1:9200/test/_search?pretty=1' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"name.ngram" : { | |
"query" : "office" | |
} | |
} | |
} | |
} | |
' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 0, | |
"max_score" : null, | |
"hits" : [ ] | |
} | |
} | |
// How come this doesn't have any matches either? It's the unanalyzed version | |
curl -XGET 'http://127.0.0.1:9200/test/_search?pretty=1' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"name.untouched" : { | |
"query" : "office" | |
} | |
} | |
} | |
} | |
' | |
{ | |
"took" : 0, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 0, | |
"max_score" : null, | |
"hits" : [ ] | |
} | |
} | |
// Only something like this has a match | |
curl -XGET 'http://127.0.0.1:9200/test/_search?pretty=1' -d ' | |
{ | |
"query" : { | |
"text" : { | |
"name" : { | |
"query" : "office" | |
} | |
} | |
} | |
} | |
' | |
{ | |
"took" : 0, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 2, | |
"max_score" : 0.30685282, | |
"hits" : [ { | |
"_index" : "test", | |
"_type" : "test", | |
"_id" : "-h5HOUGKSxavy_EPhj5H7w", | |
"_score" : 0.30685282, "_source" : { "name" : "The Office" } | |
}, { | |
"_index" : "test", | |
"_type" : "test", | |
"_id" : "RJ40-EeDSwW8OHyePF4KRQ", | |
"_score" : 0.19178301, "_source" : { "name" : "The Office (UK)" } | |
} ] | |
} | |
} | |
// Am I not using ngram or multifield correctly? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment