2014-07-09 159 views
0

我使用蒙戈,彈性搜索和這條河插件字段映射:https://github.com/richardwilly98/elasticsearch-river-mongodbElasticSearch河搞亂

我已經成功地設置好一切在這條河一直蒙戈時更新更新ES數據,但這條河直接將Mongo文檔中的所有屬性複製到ES中,但我只需要這些記錄的一小部分。例如。如果一個Mongo文檔有30個屬性,它們都將被放入ES中,而不僅僅是我想要的5個。我認爲這個問題與映射有關,並且我遵循了幾個文檔和另一個堆棧溢出線程(curl -X POST -d @mapping.json + mapping not created),但它仍然不適合我。下面是我在做什麼:

我創建我的指數有:

curl -XPOST "http://localhost:9200/mongoindex" -d @index.json 

index.json:

{ 
    "settings" : { 
     "number_of_shards" : 1 
    }, 
    "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 
     } 
    } 
    } 
} 

然後運行:

curl -XPOST "http://localhost:9200/mongoindex/listing/_mapping" -d @mapping.json 

有了這個數據:

{ 
    "listing":{ 
     "properties":{ 
     "_all": { 
      "enabled": false 
     }, 
     "title": { 
      "type": "string", 
      "store": false, 
      "index": "not_analyzed" 
     }, 
     "bathrooms": { 
      "type": "integer", 
      "store": true, 
      "index": "analyzed" 
     }, 
     "bedrooms": { 
      "type": "integer", 
      "store": true, 
      "index": "analyzed" 
     }, 
     "address": { 
      "type": "nested", 
      "include_in_parent": true, 
      "store": true, 
      "properties": { 
       "counrty": { 
       "type":"string" 
       }, 
       "city": { 
       "type":"string" 
       }, 
       "stateOrProvince": { 
       "type":"string" 
       }, 
       "fullStreetAddress": { 
       "type":"string" 
       }, 
       "postalCode": { 
       "type":"string" 
       } 
      } 
     }, 
     "location": { 
      "type": "geo_point", 
      "full_name": "geometry.coordiantes", 
      "store": true 
     } 
     } 
    } 
} 

後來終於與創建河流:

curl -XPUT "http://localhost:9200/_river/mongoindex/_meta" -d @river.json 

river.json:

{ 
    "type": "mongodb", 
    "mongodb": { 
    "db": "blueprint", 
    "collection": "Listing", 
    "options": { 
     "secondary_read_preference": true, 
     "drop_collection": true 
    } 
    }, 
    "index": { 
    "name": "mongoindex", 
    "type": "listing" 
    } 
} 

畢竟,這條河在ES是人口工作,但現在它的蒙戈的完整副本,我需要修改映射,但它不會生效。我錯過了什麼?

這是我的地圖在河流運行後的樣子....沒有什麼像我想要的樣子。

ES mapping

enter image description here

+0

你能再試一次,但在創建河之前獲得與此命令的映射並添加到您的問題? curl -XGET'http:// localhost:9200/_mapping?pretty' –

+0

我得到了預期的結果,那個映射在第二個命令後是正確的。它在創建河流時重置它。看第二張截圖。 –

回答

0

匝問題是動態屬性被遺漏在映射配置中。它應該是在兩個地方,在index.json如上圖所示,並在mappings.json:

{ 
    "listing":{ 
     "_source": { 
     "enabled": false 
     }, 
     "dynamic": false,  // <--- Need to add this 
     "properties":{ 
     "_all": { 
      "enabled": false 
     }, 
     "title": { 
      "type": "string", 
      "store": false, 
      "index": "str_index_analyzer" 
     }, 
     "bathrooms": { 
      "type": "integer", 
      "store": true, 
      "index": "analyzed" 
     }, 
     "bedrooms": { 
      "type": "integer", 
      "store": true, 
      "index": "analyzed" 
     }, 
     "address": { 
      "type": "nested", 
      "include_in_parent": true, 
      "store": true, 
      "properties": { 
       "counrty": { 
       "type":"string", 
       "index": "str_index_analyzer" 
       }, 
       "city": { 
       "type":"string", 
       "index": "str_index_analyzer" 
       }, 
       "stateOrProvince": { 
       "type":"string", 
       "index": "str_index_analyzer" 
       }, 
       "fullStreetAddress": { 
       "type":"string", 
       "index": "str_index_analyzer" 
       }, 
       "postalCode": { 
       "type":"string" 
       } 
      } 
     }, 
     "location": { 
      "type": "geo_point", 
      "full_name": "geometry.coordiantes", 
      "store": true 
     } 
     } 
    } 
} 

的902個文檔VS 451,我認爲這是在ElasticSearch頭插件,我是一個錯誤用來瀏覽文件。它沒有重複,但有幾個點顯示902個文檔作爲各種摘要。

0

我會設置動態映射到錯誤:

動態創建映射未映射類型可以通過設置index.mapper.dynamic爲false完全 禁用。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html

其他有過類似的問題,以你的,它看起來像最好的解決方案至今,一直以防止MongoDB的河從動態映射都:

https://github.com/richardwilly98/elasticsearch-river-mongodb/issues/75

+0

我在此建議之前添加了dynamic:false設置,它似乎可行,但現在問題是河流輸入的文檔數量是兩倍。例如。 Mongo有451個文檔,然後在河流902後有mongoindex。 –