2017-09-14 47 views
0

我目前在elasticsearch中使用語言分析器。在這裏我發現,如果我們需要使用分析器來搜索文檔,那麼我們需要定義映射和分析器。 在我的情況下,如果文檔包含一個普通的文本字段,這可以正常工作,但是當我將相同的屬性應用於嵌套字段時,分析器不起作用。如何在語言分析器中使用嵌套映射

這是語言分析器

PUT checkmap 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "stemmerenglish": { 
      "tokenizer": "standard", 
      "filter": [ 
      "standard", 
      "lowercase", 
      "my_stemmer" 
      ] 
     } 
     }, 
     "filter": { 
     "my_stemmer": { 
      "type": "stemmer", 
      "name": "english" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "dd": { 
     "properties": { 
     "Courses": { 
      "type": "nested", 
      "properties": { 
      "Sname": { 
       "type": "text", 
       "analyzer": "stemmerenglish", 
       "search_analyzer": "stemmerenglish" 
      } 
      } 
     } 
     } 
    } 
    } 
} 

代碼請幫我出上述問題。

+0

您提供上面的映射。你怎麼知道你的分析儀不工作。你運行哪個查詢不起作用?請分享一下。 – Richa

+0

PUT checkmap/DD/2 { 「課程」:[ { 「SNAME」: 「跳」 } ] } GET checkmap3/_search { 「查詢」:{ 「匹配」: { 「Courses.Sname」:{ 「查詢」: 「跳轉」 }} } } 謝謝 – honey

回答

2

您必須使用Nested Query作爲嵌套類型。使用下面的查詢

GET checkmap/_search 
{ 
"query": { 
    "nested": { 
    "path": "Courses", 
    "query": { 
     "match": { 
      "Courses.Sname": { 
       "query": "Jump" 
      } 
      } 
     } 
     } 
    } 
    } 

更多here

+0

ü。它的工作現在。 – honey

+0

你可以接受答案然後.. :) – Richa