php - understanding ElasticSearch routing -
i trying use elasticsearch routing mapping speed queries, not getting expected result set (not worried query performance yet)
i using elastic set mapping:
$index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'mappings'=>array("country"=>array("_routing"=>array("path"=>"countrycode"))), 'analysis' => array( 'analyzer' => array( 'indexanalyzer' => array( 'type' => 'keyword', 'tokenizer' => 'ngram', 'filter' => array('shingle') ), 'searchanalyzer' => array( 'type' => 'keyword', 'tokenizer' => 'ngram', 'filter' => array('shingle') ) ) ) ), true); if understand correctly, should happen each result should have field called "countrycode" value of "country" in it.
the results of _mapping this:
{"postcode": {"postcode": {"properties": { "area1":{"type":"string"}, "area2":{"type":"string"}, "city":{"type":"string", "include_in_all":true}, "country":{"type":"string"}, "country_iso":{"type":"string"}, "country_name":{"type":"string"}, "id":{"type":"string"}, "lat":{"type":"string"}, "lng":{"type":"string"}, "location":{"type":"geo_point"}, "region1":{"type":"string"}, "region2":{"type":"string"}, "region3":{"type":"string"}, "region4":{"type":"string"}, "state_abr":{"type":"string"}, "zip":{"type":"string","include_in_all":true}}}, "country":{ "_routing":{"path":"countrycode"}, "properties":{} } } } once data in index if run command:
http://localhost:9200/postcode/_search?pretty=true&q=country:au it responds 15740 total items
what expecting if run query this:
http://localhost:9200/postcode/_search?routing=au&pretty=true then expecting respond 15740 results
instead returns 120617 results, includes results country != au
i did note number of shards in results went 4 1, working.
i expecting in result set there item called "countrycode" (from rounting mapping) there isn't
so thought @ point understand of routing wrong. perhaps routing tell shard in not for? in other words if other country codes happen land in particular shard, way queries written bring records in shard?
so tried query again, time adding info it.
http://localhost:9200/postcode/_search?routing=au&pretty=true&q=country:au i thought doing force query giving me au place names, time gave me 3936 results
so not quite sure have done wrong, examples have read show queries changing needing filter, using match_all{} have thought being ones matching au country code.
thanks in getting work correctly.
almost have working, gives me correct number of results in single shard, create index not working quite right, ignores number_of_shards setting, , possibly other ones too
$index = $client->getindex($indexname); $index->create(array('mappings'=>array("$indexname"=>array("_routing"=>array("required"=>true))),'number_of_shards' => 6, 'number_of_replicas' => 1, 'analysis' => array( 'analyzer' => array( 'indexanalyzer' => array( 'type' => 'keyword', 'tokenizer' => 'ngram', 'filter' => array('shingle') ), 'searchanalyzer' => array( 'type' => 'keyword', 'tokenizer' => 'ngram', 'filter' => array('shingle') ) ) ) ), true);
i can @ least more info on look:
http://localhost:9200/postcode/_search?routing=au&pretty=true that query indeed translate "give me documents on shard documents country:au should sent."
routing that, routing ... doesn't filter results you.
also noticed you're mixing "au"s , "au"s .. might mix things too.
you should try setting required on routing element true, make sure documents stored routing information when being indexed.
actually make sure documents indexed proper routing explicitly set route lowercase(countrycode) when indexing documents. see if helps any.
for more information try reading blog post:
http://www.elasticsearch.org/blog/customizing-your-document-routing/
hope helps :)
Comments
Post a Comment