Hi
I have been trying to fix this issue for more than 20 days , but couldn't make it working.
Also I am new to Elasticsearch as this is our first project to implement.
Step 1 :
I have Installed Elasticsearch 2.0 in Ubuntu 14.04. I able to create new Index using below code
$hosts = array('our ip address:9200');
$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$index = "IndexName";
$params['index'] = $index;
$params['type'] = 'xyz';
$params['body']["id"] = "1";
$params['body']["title"] = "C++ Developer - C# Developer";
$client->index($params);
once the above code runs Index successfully created.
Step 2 :
Able to look into the created Index using below link
`http://our ip address:9200/IndexName/_search?q=C%23&pretty
{
"took" : 30,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 9788,
"max_score" : 0.8968174,
"hits" : [ {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1545680",
"_score" : 0.8968174,
"_source":{"id":"1545680","title":"C\+\+ and C\# \- Software Engineer"}
}, {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1539778",
"_score" : 0.853807,
"_source":{"id":"1539778","title":"Rebaca Technologies Hiring in C\+\+"}
}
....
http://our ip address:9200/IndexName/_search?q=C%23&pretty
{
"took" : 30,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 9788,
"max_score" : 0.8968174,
"hits" : [ {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1545680",
"_score" : 0.8968174,
"_source":{"id":"1545680","title":"C\+\+ and C\# \- Software Engineer"}
}, {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1539778",
"_score" : 0.853807,
"_source":{"id":"1539778","title":"Rebaca Technologies Hiring in C\+\+"}
}
....
If you note the above search result i am getting 2nd result which is not having c#. Even i am getting the same result for search "C" only
I am not getting relavant search result according to the keywords which contains special characters like +, #, or .
I am preserving the special characters as per the below guide
Escaping Special Characters
Lucene supports escaping special characters that are part of the query syntax. The current list special characters are
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
`
To escape these character use the \ before the character. For example to search for (1+1):2 use the query:
`(1+1):2
`I added # in the group of escape charaters.
Step 3:
In php while passing the special characters into Elasticsearch search function i am escaping like below
$keyword = str_replace(""",'"',$keyword);
$keyword = str_replace("+","+",$keyword);
$keyword = str_replace(".",".",$keyword);
$keyword = str_replace("#","#",$keyword);
$keyword = str_replace("/","/",$keyword);
$keyword = trim($keyword);
$params['body']['query']['query_string'] = array("query" => $keyword,"default_operator" => "AND" ,"fields" => array("title"));
$client->search($params); `
Please help me how to make the special character work
Thanks