2016-02-12 74 views
0

我相信是許多使用彈性搜索的用例。這裏是我的模板彈性搜索與英文分析器匹配的確切字符串

PUT _template/test 
{ 
    "template" : "test*", 
    "settings" : { 
     "number_of_shards" : 5, 
     "number_of_replicas" : 1 
    }, 
    "mappings" : { 
     "test": { 
     "properties": { 
      "name": { 
      "type": "string", 
      "index": "analyzed" 
      }, 
     "description": { 
      "type": "string", 
      "index": "analyzed", 
      "analyzer":"english", 
      "fields": { 
       "raw": { 
       "type": "string", 
       "index": "not_analyzed" 
       } 
      } 
      } 
     } 
     } 
    } 
} 

現在我打算把單條記錄在索引

POST /test/test 
{ 
    "name":"test-1", 
    "description":"on the first day of christmas my true love gave to me a partridge in a pear tree" 
} 

現在想象一下,我有這些記錄一百萬。我想要做的是,如果我在描述字段上搜索on the,我不想回來,因爲這些是英語分析器應該處理的常見詞彙。但是,如果我搜索確切的文字"on the",那麼我希望返回的文檔與確切的文字相匹配。

我對彈性社區的問題是如何允許這個以及查詢應該是什麼樣子?我添加了描述的.raw字段,但不管我的查詢字符串是什麼,我都無法得到確切的文本來返回任何結果。

+0

你要查詢像GET /測試/測試/ _search'{ 「查詢」:{ 「術語」:{ 「description.raw」: 「上的」 } }}' – Richa

+0

當我運行的確切查詢我得到'{ 「花」:1, 「TIMED_OUT」:假的, 「_shards」:{ 「總」:5, 「成功」:5, 「失敗」:0 }, 「命中」:{ 「總」:0, 「MAX_SCORE」:空, 「點擊」:[] } }' –

+0

這可能是因爲你沒有任何說明與確切的文本 – Richa

回答

0

你的第一個要求已經被英文分析儀滿足了。現在來解決第二個問題,如果「通過」,你想獲得完整匹配的文件。在第二個問題的情況下,應該在「description。raw」字段中進行搜索。將您的字段標記爲「原始」:{ 「type」:「string」, 「index」:「analysed」 }此處默認分析器是標準的,因此您將獲得整個文檔的「on」或「the」或「在」匹配,但如果你想匹配包含確切文件「對」字配置新的自定義分析儀‘’使用領域‘邊緣NGRAM’標記者description.raw。 更多細節可以在下面的鏈接中找到 https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html

相關問題