Commit aad8653c authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

fix: use a custom analyzer to be able to suggest numbers, which are removed by...

fix: use a custom analyzer to be able to suggest numbers, which are removed by the default simple analyzer
parent 7f0fe397
......@@ -153,10 +153,14 @@ curl -X PUT "localhost:9200/rare-resource-physical-index" -H 'Content-Type: appl
"rare-resource-index" : {},
"rare-resource-harvest-index" : {}
}
"settings": ...
}
'
```
**NOTE**: Every time a physical index is created, the settings must be specified, the same ay as in the
`createIndexAndAliases.sh` script. The exact content of the settings is omitted here for brevity and readability.
#### Deleting with no downtime
If you don't want any downtime, you can instead use the following procedure:
......@@ -174,7 +178,9 @@ Here are curl commands illustrating the above scenario:
```
# create a new physical index
curl -X PUT "localhost:9200/rare-resource-new-physical-index" -H 'Content-Type: application/json' -d'
{}
{
"settings": ...
}
'
# delete the `rare-resource-harvest-index` alias, and recreate it so that it refers to `rare-resource-new-physical-index`
......@@ -224,7 +230,9 @@ Here are curl commands illustrating the above scenario:
```
# create a new physical index
curl -X PUT "localhost:9200/rare-resource-new-physical-index" -H 'Content-Type: application/json' -d'
{}
{
"settings": ...
}
'
# delete the `rare-resource-harvest-index` and the `rare-resource-index` aliases, and recreate them both so that they refer to `rare-resource-new-physical-index`
......@@ -264,7 +272,9 @@ Here are curl commands illustrating the above scenario:
```
# create a new physical index
curl -X PUT "localhost:9200/rare-resource-new-physical-index" -H 'Content-Type: application/json' -d'
{}
{
"settings": ...
}
'
# delete the `rare-resource-harvest-index` alias, and recreate it so that it refers to `rare-resource-new-physical-index`
......
......@@ -148,7 +148,8 @@
"type": "geo_point"
},
"suggestions": {
"type" : "completion"
"type" : "completion",
"analyzer": "custom_suggestion_analyzer"
}
}
}
......@@ -62,7 +62,8 @@
}
},
"suggestions": {
"type" : "completion"
"type" : "completion",
"analyzer": "custom_suggestion_analyzer"
}
}
}
package fr.inra.urgi.rare.dao;
import java.io.IOException;
import java.io.UncheckedIOException;
import org.elasticsearch.common.settings.Settings;
/**
* Utility class to load the settings from the resources
* @author JB Nizet
*/
public class GeneticResourceIndexSettings {
public static String createSettings() {
try {
return Settings.builder().loadFromStream(
"settings.json",
GeneticResourceIndexSettings.class.getResourceAsStream("settings.json"),
true
).build().toString();
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
......@@ -11,6 +11,7 @@ import java.util.function.BiConsumer;
import fr.inra.urgi.rare.config.AppProfile;
import fr.inra.urgi.rare.config.ElasticSearchConfig;
import fr.inra.urgi.rare.dao.GeneticResourceIndexSettings;
import fr.inra.urgi.rare.dao.SearchRefinements;
import fr.inra.urgi.rare.domain.Location;
import fr.inra.urgi.rare.domain.rare.RareGeneticResource;
......@@ -61,7 +62,7 @@ class RareGeneticResourceDaoTest {
ElasticsearchPersistentEntity geneticResourceEntity = elasticsearchTemplate.getPersistentEntityFor(
RareGeneticResource.class);
elasticsearchTemplate.deleteIndex(PHYSICAL_INDEX);
elasticsearchTemplate.createIndex(PHYSICAL_INDEX);
elasticsearchTemplate.createIndex(PHYSICAL_INDEX, GeneticResourceIndexSettings.createSettings());
elasticsearchTemplate.addAlias(
new AliasBuilder().withAliasName(indexedGeneticResourceEntity.getIndexName())
.withIndexName(PHYSICAL_INDEX)
......
......@@ -10,6 +10,7 @@ import java.util.function.BiConsumer;
import fr.inra.urgi.rare.config.AppProfile;
import fr.inra.urgi.rare.config.ElasticSearchConfig;
import fr.inra.urgi.rare.dao.GeneticResourceDao;
import fr.inra.urgi.rare.dao.GeneticResourceIndexSettings;
import fr.inra.urgi.rare.dao.SearchRefinements;
import fr.inra.urgi.rare.dao.rare.RareGeneticResourceDao;
import fr.inra.urgi.rare.domain.GeneticResource;
......@@ -62,7 +63,7 @@ class WheatisGeneticResourceDaoTest {
ElasticsearchPersistentEntity geneticResourceEntity = elasticsearchTemplate.getPersistentEntityFor(
WheatisGeneticResource.class);
elasticsearchTemplate.deleteIndex(PHYSICAL_INDEX);
elasticsearchTemplate.createIndex(PHYSICAL_INDEX);
elasticsearchTemplate.createIndex(PHYSICAL_INDEX, GeneticResourceIndexSettings.createSettings());
elasticsearchTemplate.addAlias(
new AliasBuilder().withAliasName(indexedGeneticResourceEntity.getIndexName())
.withIndexName(PHYSICAL_INDEX)
......
{
"analysis": {
"analyzer": {
"custom_suggestion_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
}
......@@ -2,11 +2,27 @@
BASEDIR=$(dirname "$0")
# NOTE: If the settings are changed here, they must also be changed the same way in
# backend/src/test/resources/fr/inra/urgi/rare/dao/settings.json for the unit tests
curl -X PUT "localhost:9200/rare-resource-physical-index" -H 'Content-Type: application/json' -d'
{
"aliases" : {
"rare-resource-index" : {},
"rare-resource-harvest-index" : {}
},
"settings": {
"analysis": {
"analyzer": {
"custom_suggestion_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
}
}
'
......@@ -16,6 +32,19 @@ curl -X PUT "localhost:9200/wheatis-resource-physical-index" -H 'Content-Type: a
"aliases" : {
"wheatis-resource-index" : {},
"wheatis-resource-harvest-index" : {}
},
"settings": {
"analysis": {
"analyzer": {
"custom_suggestion_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
}
}
'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment