Configuration for synonym


(vgross) #1

I ! I try to use Elastic Search for my Website and i have a configuration problem !

First i edit the file '/usr/local/elasticsearch/config/elasticsearch.yml' with :

cluster.name: mycluster

Then I edit '/etc/elasticsearch/elasticsearch.yml' with :

cluster:
name: mycluster

index:
analysis:
analyzer:
syns:
tokenizer : standard
filter : syn_filter

    filter:
        syn_filter:
            type: synonym
            synonyms_path: /etc/elasticsearch/synonym.txt

finally i edit my synonym file '/etc/elasticsearch/synonym.txt' with :

cool => sympa

In my script 'index.php' , i use https://github.com/nervetattoo/elasticsearch, first i execute :

require_once "ElasticSearchClient.php";

$transport = new ElasticSearchTransportHTTP("localhost", 9200);
$search = new ElasticSearchClient($transport, "myindex", "mytype");
var_dump($search->index(array('title' => 'My cool document')));
var_dump($search->index(array('title' => 'My second cool document')));

and the result is :

array(5) {
["ok"]=>
bool(true)
["_index"]=>
string(7) "myindex"
["_type"]=>
string(6) "mytype"
["_id"]=>
string(22) "olRN5Z2WQo61b74MKnp2DQ"
["_version"]=>
int(1)
}
array(5) {
["ok"]=>
bool(true)
["_index"]=>
string(7) "myindex"
["_type"]=>
string(6) "mytype"
["_id"]=>
string(22) "Ly-Q-mISSm2Jt4HnEcaqww"
["_version"]=>
int(1)
}

But here, it's ok, my 2 documents are now in my index "myindex"
Then i execute my script like this :

require_once "ElasticSearchClient.php";

$transport = new ElasticSearchTransportHTTP("localhost", 9200);
$search = new ElasticSearchClient($transport, "myindex", "mytype");

var_dump($search->search('title:cool'));
var_dump($search->search('title:sympa'));

and the result is :
array(5) {
["took"]=>
int(2)
["timed_out"]=>
bool(false)
["_shards"]=>
array(3) {
["total"]=>
int(5)
["successful"]=>
int(5)
["failed"]=>
int(0)
}
["hits"]=>
array(3) {
["total"]=>
int(2)
["max_score"]=>
float(0.2972674)
["hits"]=>
array(2) {
[0]=>
array(5) {
["_index"]=>
string(7) "myindex"
["_type"]=>
string(6) "mytype"
["_id"]=>
string(22) "9nPVEj6DT-65KfKuJvJ9QQ"
["_score"]=>
float(0.2972674)
["_source"]=>
array(1) {
["title"]=>
string(16) "My cool document"
}
}
[1]=>
array(5) {
["_index"]=>
string(7) "myindex"
["_type"]=>
string(6) "mytype"
["_id"]=>
string(22) "f67TBpqMQimBiBkD5FZv_g"
["_score"]=>
float(0.2972674)
["_source"]=>
array(1) {
["title"]=>
string(23) "My second cool document"
}
}
}
}
["time"]=>
float(0.0040738582611084)
}
array(5) {
["took"]=>
int(1)
["timed_out"]=>
bool(false)
["_shards"]=>
array(3) {
["total"]=>
int(5)
["successful"]=>
int(5)
["failed"]=>
int(0)
}
["hits"]=>
array(3) {
["total"]=>
int(0)
["max_score"]=>
NULL
["hits"]=>
array(0) {
}
}
["time"]=>
float(0.0020260810852051)
}

I don't understand why my second request don't find my cool document ? I think i make a mistake but after 1 day of search, i don't find it ! Please help me !

PS: when i try URL : http://192.168.1.35:9200/_analyze?pretty=1&text=cool&analyzer=syns the result is :

{
"error" : "ElasticSearchIllegalArgumentException[failed to find analyzer [syns]]",
"status" : 400
}

Thanx


(system) #2