2017-04-11 108 views
2

我在我的索引中有一個簡單的「text」字段。ElasticSearch匹配分數

"keywordName": { 
      "type": "text" 
     } 

,我已經插入這些文檔:「三星」,「三星Galaxy」,「三星蓋」,「三星充電器」。

如果我做一個簡單的 「匹配」 查詢,結果令人不安:

查詢:

GET keywords/_search 
{ 
    "query": { 
    "match": { 
     "keywordName": "samsung" 
    } 
    } 
} 

結果:

{ 
    "took": 7, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 4, 
    "max_score": 1.113083, 
    "hits": [ 
     { 
     "_index": "keywords", 
     "_type": "keyword", 
     "_id": "samsung galaxy", 
     "_score": 1.113083, 
     "_source": { 
      "keywordName": "samsung galaxy" 
     } 
     }, 
     { 
     "_index": "keywords", 
     "_type": "keyword", 
     "_id": "samsung charger", 
     "_score": 0.9433406, 
     "_source": { 
      "keywordName": "samsung charger" 
     } 
     }, 
     { 
     "_index": "keywords", 
     "_type": "keyword", 
     "_id": "samsung", 
     "_score": 0.8405092, 
     "_source": { 
      "keywordName": "samsung" 
     } 
     }, 
     { 
     "_index": "keywords", 
     "_type": "keyword", 
     "_id": "samsung cover", 
     "_score": 0.58279467, 
     "_source": { 
      "keywordName": "samsung cover" 
     } 
     } 
    ] 
    } 
} 

第一個問題:爲什麼 「三星」 還沒有最高分?

第二個問題:如何製作查詢或分析儀,使我的「三星」成爲最高分?

+0

你基本上是問同樣的問題,因爲http://stackoverflow.com/questions/43257656/elasticsearch-analyzer-on-text-field。你的第一個問題的答案是https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html。對你的第二個問題的回答是我已經回覆的另一篇文章。 –

+0

問題是相同的,但如果我採用與其他索引相同的索引和分析器,並且搜索「samsungs」,則令牌爲「samsung」,所以術語查詢不起作用,匹配查詢返回「samsung galaxy「... – Gun

+0

這就是爲什麼在開始提出索引映射和這些需求查詢列表之前,制定所有要求的重要原因。 –

回答

1

從我的previous reply中的相同索引設置(分析器,過濾器和映射)開始,我建議採用以下解決方案。但是,正如我所提到的,您需要根據您在此索引中搜索的內容制定所有要求,並將所有這些視爲一個完整的解決方案。

DELETE test 
PUT test 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "custom_stop": { 
      "type": "custom", 
      "tokenizer": "standard", 
      "filter": [ 
      "my_stop", 
      "my_snow", 
      "asciifolding" 
      ] 
     } 
     }, 
     "filter": { 
     "my_stop": { 
      "type": "stop", 
      "stopwords": "_french_" 
     }, 
     "my_snow": { 
      "type": "snowball", 
      "language": "French" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "test": { 
     "properties": { 
     "keywordName": { 
      "type": "text", 
      "analyzer": "custom_stop", 
      "fields": { 
      "raw": { 
       "type": "keyword" 
      } 
      } 
     } 
     } 
    } 
    } 
} 
POST /test/test/_bulk 
{"index":{}} 
{"keywordName":"samsung galaxy"} 
{"index":{}} 
{"keywordName":"samsung charger"} 
{"index":{}} 
{"keywordName":"samsung cover"} 
{"index":{}} 
{"keywordName":"samsung"} 

GET /test/_search 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "keywordName": { 
       "query": "samsungs", 
       "operator": "and" 
      } 
      } 
     }, 
     { 
      "term": { 
      "keywordName.raw": { 
       "value": "samsungs" 
      } 
      } 
     }, 
     { 
      "fuzzy": { 
      "keywordName.raw": { 
       "value": "samsungs", 
       "fuzziness": 1 
      } 
      } 
     } 
     ] 
    } 
    }, 
    "size": 10 
} 
+0

我同意你的要求。問題在於,對我而言這是一種演變。我沒有完整的一批數據,這是設置詳盡的需求清單的相當大的問題。 – Gun