[root@web_data esshell]# cat softwaremapping.sh
curl -XPUT http://10.19.21.94:9200/software -d '
{
"settings": {
"analysis": {
"analyzer": {
"caseSensitive": {
"filter": "lowercase",
"type": "custom",
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"personInfo": {
"properties": {
"name": {
"type": "string",
"index": "analyzed",
"analyzer" : "ik"
},
"newname": {
"type": "string",
"analyzer":"caseSensitive",
"search_analyzer":"caseSensitive"
}
}
}
}
}'
[root@web_data esshell]#
[root@web_data bin]# cat software.sh
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bin=${DIR}/../bin
lib=${DIR}/../lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://10.10.10.10:3306/software",
"user" : "root",
"password" : "123456",
"sql" : "select id,name,name as newname from software where 1",
"index" : "software",
"type" : "category",
"elasticsearch" : {
"cluster" : "elasticsearch",
"host" : "10.19.21.1",
"port" : 9300
}
}
}' | /home/test/jdk1.8.0_121/bin/java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
[root@web_data bin]#
search.php
$params = array(
'query' => array(
'bool' => array(
'should' => array(
array('match' =>array( 'name' => $word )),
)
)
),
'highlight' => array(
'fields' => array(
'name' => array(
"pre_tags" => "<strong>",
"post_tags"=> "</strong>"
),
)
),
);
$url ="http://10.19.21.1:9200/software/category/_search?size=100&from=0";
$json_data = json_encode ($params);
//$word = 'Q';
$json_data = "{\"query\":{\"bool\":{\"must\":[],\"must_not\":[],\"should\":[{\"match\":{\"name\":\"$word\"}},{\"wildcard\":{\"newname\":\"*$word*\"}}]}},\"from\":0,\"size\":100,\"sort\":[],\"aggs\":{}}";
$result = $this->curl ( $url, $json_data, "GET" );
$object = json_decode($result);
$array = get_object_vars($object);
$hits = get_object_vars($array["hits"]);
$list = $hits["hits"];
$total = $hits["total"];
foreach($list as $key=>$value){
$valuearray = get_object_vars($value);
$source = get_object_vars($valuearray["_source"]);
}
https://blog.csdn.net/sunnyyoona/article/details/51842221
curl -XPUT 'localhost:9200/test-index' -d'
{
"mappings":{
"stu":{
"properties":{
"name":{
"type":"string"
},
"sex":{
"type":"string"
},
"college":{
"type":"string",
"index":"not_analyzed"
}
}
}
}