Last active
October 5, 2016 14:27
-
-
Save phpdave/53b23558afc19dcd484d60cabc766859 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
<? | |
$pdo = new PDO("odbc:" . $HostName, $User, $Password); | |
$stmt = $pdo->query('SELECT * FROM MYTABLE'); | |
$rows = $stmt->fetchAll(); | |
//convert to utf8 | |
array_walk_recursive($rows, function(&$value, $key) { | |
if (is_string($value)) { | |
$value = iconv('windows-1252', 'utf-8', $value); | |
} | |
}); | |
$index=0; | |
foreach ($array as $row) | |
{ | |
$header = array("index"=>array("_index"=>"myindex","_type"=>"mytype","_id"=>(string)$index++)); | |
//Header | |
echo json_encode($header).PHP_EOL; | |
//Data | |
echo json_encode($row).PHP_EOL; | |
} | |
//Take Json data and bulk import it | |
//curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json" | |
//curl 'localhost:9200/_cat/indices?v' | |
exit(); |
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
#create customer | |
? curl -XPUT "localhost:9200/customer?pretty" | |
{ | |
"acknowledged" : true, | |
"shards_acknowledged" : true | |
} | |
#view indices | |
? curl "localhost:9200/_cat/indices?v" | |
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size | |
yellow open customer RqYz-8QcSq-BrmMhbRDRQw 5 1 0 0 650b 650b | |
#add John Doe | |
? curl -XPUT "localhost:9200/customer/external/1?pretty" -d " { \"name\": \"John Doe\" }" | |
{ | |
"_index" : "customer", | |
"_type" : "external", | |
"_id" : "1", | |
"_version" : 1, | |
"result" : "created", | |
"_shards" : { | |
"total" : 2, | |
"successful" : 1, | |
"failed" : 0 | |
}, | |
"created" : true | |
} | |
#search for john doe by just john | |
? curl -XPOST "http://localhost:9200/customer/_search?q=john&pretty" | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.25811607, | |
"hits" : [ | |
{ | |
"_index" : "customer", | |
"_type" : "external", | |
"_id" : "1", | |
"_score" : 0.25811607, | |
"_source" : { | |
"name" : "John Doe" | |
} | |
} | |
] | |
} | |
} | |
# Search for joh d and get .172 score | |
λ curl -XPOST "http://localhost:9200/customer/_search?pretty" -d " { \"query\": { \"match\": { \"name\": { \"query\": \"joh d\", \"fuzziness\": 2, \"prefix_length\": 1 } } } } " | |
{ | |
"took" : 16, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.17207736, | |
"hits" : [ | |
{ | |
"_index" : "customer", | |
"_type" : "external", | |
"_id" : "1", | |
"_score" : 0.17207736, | |
"_source" : { | |
"name" : "John Doe" | |
} | |
} | |
] | |
} | |
} | |
# Search for joh do and get .301 score | |
λ curl -XPOST "http://localhost:9200/customer/_search?pretty" -d " { \"query\": { \"match\": { \"name\": { \"query\": \"joh do\", \"fuzziness\": 2, \"prefix_length\": 1 } } } } " | |
{ | |
"took" : 15, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.3011354, | |
"hits" : [ | |
{ | |
"_index" : "customer", | |
"_type" : "external", | |
"_id" : "1", | |
"_score" : 0.3011354, | |
"_source" : { | |
"name" : "John Doe" | |
} | |
} | |
] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment