2016-11-29 73 views
-2

我有一個問題,使用elasticsearch在這個問題上浪費了很多時間,可能你可以幫助我。Elasticsearch同義詞和類別提升

我與很多產品索引和我設升壓基於某些類別與此搜索:

{ 
    "from": 1, 
    "size": 10 
    "query": { 
     "bool": { 
      'must': { 
       'match': { 
        'NAME': { 
         "query": "tv", 
         "operator": "and" 
        } 
       }, 
      }, 
      "should": { 
       "query_string": { 
        "query": 'category: 23', 
        "boost": 2 
       } 
      } 
     } 
} 

這項工作很好,結果的得分已經改變了這些類別。

現在我們想介紹搜索的同義詞,我們用這個方法來設置synoynyms作爲分析儀elasticsearch:

"analysis": { 
    "analyzer": { 
     "synonym": { 
       "tokenizer": "whitespace", 
       "filter": ["lowercase", "asciifolding", "synonym_filter"] 
     } 
    }, 
    "filter": { 
     "synonym_filter": { 
      "type": "synonym", 
      "language": "spanish", 
      "synonyms": [ 
       "tv, television, tdt" 
      ] 
     } 
    } 
} 

我們查詢更改爲使用新的分析和這項工作很好:

{ 
    "from": 1, 
    "size": 10 
    'query': { 
     'bool': { 
      'must': { 
       'match': { 
        'NAME': { 
         "query": "television", 
         "operator": "and", 
         "analyzer": "synonym" 
        } 
       } 
      } 
     } 
    } 
} 

但是,當我們嘗試應用推動這個查詢犯規變化

{ 
    "from": 1, 
    "size": 10 
    'query': { 
     'bool': { 
      'must': { 
       'match': { 
        'NAME': { 
         "query": "television", 
         "operator": "and", 
         "analyzer" => "synonym" 
        } 
       }, 
      }, 
      "should": { 
       "query_string": { 
        "query": 'category: 23', 
        "boost" => 2 
       } 
      } 
     } 
    } 
} 
結果210

有人可以幫我嗎?

問候。

+0

您使用的是自定義分析器嗎? – Kulasangar

回答

0

索引Boost -ing已在新版本的5.0中棄用,其中field mapping boost可用。我想你知道這件事。

索引時間提升已棄用。

如果是同時提高索引的字段級,不應該查詢如:

"should": { 
       "query_string": { 
        "query": 'category: 23', 
        "boost": 2 
       } 
      } 

如果不是這種情況,應與analyzer即可。你不是應該具有analysissettings標籤內:

PUT /index 
{ 
    "settings": { 
     "analysis": { 
      "analyzer": {     
      } 
     } 
    } 
} 

could be helpful

+0

嗨,我認爲你是錯的,索引增強已經改爲在elasticsearch 5.0中查詢增強: https://www.elastic.co/guide/en/elasticsearch/reference/5.0/index-boost.html 事實上,沒有同義詞的助推器的操作是正確的,並且100%令人滿意 另一方面,在彈性5中,索引參數的更新沒有設置,因爲它指定了官方文檔 https: //www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html –

+0

@JuanjoAguilellaMarésoops謝謝:)我錯誤地寫了答案。在我的答案的後半部分提到的設置工作中是否包含了您的分析? – Kulasangar

+0

在您提供的[link](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html)中,PUT url(localhost:9200/myindex/_settings )應該包含設置,不是嗎?如果你這樣做,那應該沒問題。 – Kulasangar