2013-01-04 70 views
7

我想使用以下命令使用mongodb-river在elasticsearch中索引mongodb,但文檔映射沒有生效。它仍然使用默認分析器(標準)字段text通過mongodb河在彈性搜索創建索引映射沒有生效

Mongodb-river 該文檔指定創建索引,但沒有關於如何提供自定義映射的文檔。這是我試過的。是否有任何其他文件,我可以找到如何指定自定義分析儀等在使用mongodb河。

curl -XPUT "localhost:9200/_river/autocompleteindex/_meta" -d ' 
{ 
    "type": "mongodb", 
    "mongodb": { 
     "host": "rahulg-dc", 
     "port": "27017", 
     "db": "qna", 
     "collection": "autocomplete_questions" 
    }, 
    "index": { 
     "name": "autocompleteindex", 
     "type": "autocomplete_questions", 
     "analysis" : { 
       "analyzer" : { 
        "str_search_analyzer" : { 
          "tokenizer" : "keyword", 
          "filter" : ["lowercase"] 
         }, 

         "str_index_analyzer" : { 
         "tokenizer" : "keyword", 
         "filter" : ["lowercase", "ngram"] 
        } 
       }, 
       "filter" : { 
        "ngram" : { 
         "type" : "ngram", 
         "min_gram" : 2, 
         "max_gram" : 20 
        } 
       } 
      } 
    }, 
    "autocompleteindex": { 
     "_boost" : { 
      "name" : "po", 
      "null_value" : 1.0 
     }, 
     "properties": { 
       "po": { 
        "type": "double" 
       }, 
       "text": { 
        "type": "string", 
        "boost": 3.0, 
        "search_analyzer" : "str_search_analyzer", 
        "index_analyzer" : "str_index_analyzer" 
       }   
     } 
    } 
}' 

該查詢返回正確的結果是我搜索完整的單詞,但不匹配任何子字符串匹配。此外,推動因素並未顯示其效果。

我在做什麼錯?

回答

8

你必須先創建你的index settings(分析)索引:

"analysis" : { 
      "analyzer" : { 
       "str_search_analyzer" : { 
         "tokenizer" : "keyword", 
         "filter" : ["lowercase"] 
        }, 

        "str_index_analyzer" : { 
        "tokenizer" : "keyword", 
        "filter" : ["lowercase", "ngram"] 
       } 
      }, 
      "filter" : { 
       "ngram" : { 
        "type" : "ngram", 
        "min_gram" : 2, 
        "max_gram" : 20 
       } 
      } 
     } 

然後你可以define a mapping你的類型:

"autocomplete_questions": { 
    "_boost" : { 
     "name" : "po", 
     "null_value" : 1.0 
    }, 
    "properties": { 
      "po": { 
       "type": "double" 
      }, 
      "text": { 
       "type": "string", 
       "boost": 3.0, 
       "search_analyzer" : "str_search_analyzer", 
       "index_analyzer" : "str_index_analyzer" 
      }   
    } 
} 

也只有這樣,你可以創建河流:

curl -XPUT "localhost:9200/_river/autocompleteindex/_meta" -d ' 
{ 
"type": "mongodb", 
"mongodb": { 
    "host": "rahulg-dc", 
    "port": "27017", 
    "db": "qna", 
    "collection": "autocomplete_questions" 
}, 
"index": { 
    "name": "autocompleteindex", 
    "type": "autocomplete_questions"} } 

幫助嗎?

+0

非常感謝。它爲我工作。 – Rahul

+0

非常感謝的人!這真的很有用=) – rusllonrails