Добрый день!
Есть индекс:
curl -XDELETE "http://127.0.0.1:9200/tests"
curl -XPUT "http://127.0.0.1:9200/tests/" -d '{
"settings":{
"analysis":{
"filter":{
"edge":{"type":"edgeNGram", "min_gram":1, "max_gram":15},
"substring":{"type":"nGram","min_gram":1,"max_gram":15},
"synonym" : {"type" : "synonym", "synonyms":["alfa,beta","gamma,delta"]}
},
"analyzer":{
"str_edge_index_analyzer":{"filter":["lowercase","edge"],"tokenizer":"keyword"},
"edge_synonym_index":{"filter":["lowercase","synonym","edge"],"tokenizer":"keyword"},
"str_index_analyzer":{"filter":["lowercase","substring"],"tokenizer":"keyword"},
"synonym_index":{"filter":["lowercase","synonym","substring"],"tokenizer":"keyword"},
"str_search_analyzer":{"filter":["lowercase"],"tokenizer":"standard"}
}
}
},
"mappings":{
"test":{
"properties":{
"id" : {"type": "string"},
"name":{
"type":"multi_field",
"fields":{
"edge":{"type":"string", "analyzer":"str_edge_index_analyzer", "search_analyzer":"str_search_analyzer"},
"syn_edge":{"type":"string","analyzer":"edge_synonym_index","search_analyzer":"str_search_analyzer"},
"ngram":{"type":"string","analyzer":"str_index_analyzer","search_analyzer":"str_search_analyzer"},
"syn":{"type":"string","analyzer":"synonym_index","search_analyzer":"str_search_analyzer"}
}
}
}
}
}
}'
И данные в нем:
curl -XPOST "http://127.0.0.1:9200/tests/test/1" -d '{
"id": "1",
"name": "alfa"
}'
curl -XPOST "http://127.0.0.1:9200/tests/test/2" -d '{
"id": "1",
"name": "device beta"
}'
Делаю запрос по слову "beta":
curl -XPOST "http://127.0.0.1:9200/tests/test/_search?pretty=true" -d '{
"query": {
"multi_match": {
"query": "beta",
"fields": ["name.edge^100", "name.syn_edge^100", "name.ngram", "name.syn"],
"analyzer": "str_search_analyzer", "fuzziness": "0"
}
},
"explain":true,
"size":4
}'
получаю такой ответ:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.30685282,
"hits": [
{
"_shard": 2,
"_node": "fHFYjxEAQ6Oq6nc-Qf1y0Q",
"_index": "tests",
"_type": "test",
"_id": "2",
"_score": 0.30685282,
"_source": {
"id": "1",
"name": "device beta"
},
"_explanation": {
"value": 0.30685282,
"description": "sum of:",
"details": [
{
"value": 0.30685282,
"description": "max of:",
"details": [
{
"value": 0.30685282,
"description": "weight(name.syn:beta in 0) [PerFieldSimilarity], result of:",
... skip ...
},
{
"_shard": 3,
"_node": "fHFYjxEAQ6Oq6nc-Qf1y0Q",
"_index": "tests",
"_type": "test",
"_id": "1",
"_score": 0.30685282,
"_source": {
"id": "1",
"name": "alfa"
},
"_explanation": {
"value": 0.30685282,
"description": "sum of:",
"details": [
{
"value": 0.30685282,
"description": "max of:",
"details": [
{
"value": 0.0030685281,
"description": "weight(name.syn:beta in 0) [PerFieldSimilarity], result of:",
"details": [
{
... skip ...
{
"value": 0.30685282,
"description": "weight(name.syn_edge:beta^100.0 in 0) [PerFieldSimilarity], result of:",
... skip ...
]
}
}
Почему-то boost ^100 на поле name.syn_edge работает не так как я ожидаю.
Попробовал преобразовать запрос так:
curl -XPOST "http://127.0.0.1:9200/tests/test/_search?pretty=true" -d '{
"query": {
"bool": {
"should": [
{ "match": { "name.edge": { "query":"beta", "boost":100, "analyzer":"str_search_analyzer", "fuzziness":"0" } } },
{ "match": { "name.syn_edge": { "query":"beta", "boost":100, "analyzer":"str_search_analyzer", "fuzziness":"0" } } },
{ "match": { "name.ngram": { "query":"beta", "analyzer":"str_search_analyzer", "fuzziness":"0" } } },
{ "match": { "name.syn": { "query":"beta", "analyzer":"str_search_analyzer", "fuzziness":"0" } } }
]
}
},
"explain":true,
"size":4
}'
Результат аналогичный.
Что я делаю не так, почему boost учитывается как-то странно (на мой взгляд)?