PHP Snowball with French


(tybreizh29) #1

Hi
I want to apply Snowball to my field "word" which is a simple word in French.
Just below are my mapping and my settings, and at the bottom it's the function I want to call to apply Snowball to my field.
It's not working, first putSettings want me to put the body field (I don't understand why), and if I add the body field I get the message ""Validation Failed: 1: no settings to update;"", just to prove me I'm not doing the right way.
What should I change to make it work ?
thanks
marc

getMapping

Array (1)
(
| ['msf'] => Array (1)
| (
| | ['mappings'] => Array (1)
| | (
| | | ['transcription'] => Array (1)
| | | (
| | | | ['properties'] => Array (9)
...
| | | | | ['content'] => Array (2)
| | | | | (
| | | | | | ['type'] = String(6) "string"
| | | | | | ['analyzer'] = String(8) "snowball"
| | | | | )
...

getSettings

Array (1)
(
| ['msf'] => Array (1)
| (
| | ['settings'] => Array (1)
| | (
| | | ['index'] => Array (5)
| | | (
| | | | ['creation_date'] = String(13) "1447860568133"
| | | | ['uuid'] = String(22) "-yL6l3htS-SO_t4LK1Iehg"
| | | | ['number_of_replicas'] = String(1) "1"
| | | | ['number_of_shards'] = String(1) "5"
| | | | ['version'] => Array (1)
| | | | (
| | | | | ['created'] = String(7) "2000099"
| | | | )
| | | )
| | )
| )
)

my code that is supposed to do the job ...

$params = [
    "index" => [
         "analysis" => [
             "analyzer" => [
                 "msf_analyzer" => [
                     "tokenizer" => "standard",
                     "filter" => ["standard", "lowercase", "msf_filter"]
                 ]
             ],
             "filter" => [
                 "msf_filter" => [
                     "type" => "snowball",
                     "language" => "French"
                 ]
             ]
         ]
     ],
    'body' => []
 ];

$response = $client->indices()->putSettings($params);

(Zachary Tong) #2

The ES-PHP client is a "low level" client which closely emulates the HTTP API. Meaning the JSON that normally goes into the HTTP request body goes inside body of the PHP request. Try this instead:

$params = [
    'index' => 'my_index',
    'body' => [
         "analysis" => [
             "analyzer" => [
                 "msf_analyzer" => [
                     "tokenizer" => "standard",
                     "filter" => ["standard", "lowercase", "msf_filter"]
                 ]
             ],
             "filter" => [
                 "msf_filter" => [
                     "type" => "snowball",
                     "language" => "French"
                 ]
             ]
         ]
      ]
 ];

$response = $client->indices()->putSettings($params);

Notice how the index name goes into index, while the JSON request body goes into body.


(tybreizh29) #3

Thanks Zachary.
It's better for the request.
I've got an exception.
Each time I had it during my previous tests, the only solution I found was to delete the index and recreate a new index with new settings. I read a solution that uses index alias to modify the index ...
Is there a simple way to apply snowball with putSettings without restarting from 0.

[Fri Nov 20 11:30:21.259172 2015] [:error] [pid 17675] [client 10.229.100.7:49186] PHP Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Can't update non dynamic settings[[index.analysis.filter.msf_filter.type, index.analysis.filter.msf_filter.language, index.analysis.analyzer.msf_analyzer.filter.0, index.analysis.analyzer.msf_analyzer.filter.2, index.analysis.analyzer.msf_analyzer.filter.1, index.analysis.analyzer.msf_analyzer.tokenizer]] for open indices [[msf]]"}],"type":"illegal_argument_exception","reason":"Can't update non dynamic settings[[index.analysis.filter.msf_filter.type, index.analysis.filter.msf_filter.language, index.analysis.analyzer.msf_analyzer.filter.0, index.analysis.analyzer.msf_analyzer.filter.2, index.analysis.analyzer.msf_analyzer.filter.1, index.analysis.analyzer.msf_analyzer.tokenizer]] for open indices [[msf]]"},"status":400}' in /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:613\nStack trace:\n#0 in /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 615


(system) #4