2015-09-09 63 views
0

因此,我有過去幾年捕獲的訪客數據 - 超過1400萬條記錄。最重要的是,我有過去幾年的表格數據。兩者之間有一個共同的ID。ElasticSearch + Kibana顯示業務數據

現在我正在嘗試使用訪問者數據學習ElasticSearch + Kibana。數據非常簡單,但格式不正確 - PHP的$ _REQUEST和$ _SERVER數據。下面是Google bot訪問的一個示例:

{u'Entrance Time': 1407551587.7385, 
u'domain': u'############', 
u'pages': {u'6818555600ccd9880bf7acef228c5d47': {u'REQUEST': [], 
    u'SERVER': {u'DOCUMENT_ROOT': u'/var/www/####/', 
    u'Entrance Time': 1407551587.7385, 
    u'GATEWAY_INTERFACE': u'CGI/1.1', 
    u'HTTP_ACCEPT': u'*/*', 
    u'HTTP_ACCEPT_ENCODING': u'gzip,deflate', 
    u'HTTP_CONNECTION': u'Keep-alive', 
    u'HTTP_FROM': u'googlebot(at)googlebot.com', 
    u'HTTP_HOST': u'############', 
    u'HTTP_IF_MODIFIED_SINCE': u'Fri, 13 Jun 2014 20:26:33 GMT', 
    u'HTTP_USER_AGENT': u'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 
    u'PATH': u'/usr/local/bin:/usr/bin:/bin', 
    u'PHP_SELF': u'/index.php', 
    u'QUERY_STRING': u'', 
    u'REDIRECT_SCRIPT_URI': u'http://############/', 
    u'REDIRECT_SCRIPT_URL': u'############', 
    u'REDIRECT_STATUS': u'200', 
    u'REDIRECT_URL': u'############', 
    u'REMOTE_ADDR': u'############', 
    u'REMOTE_PORT': u'46271', 
    u'REQUEST_METHOD': u'GET', 
    u'REQUEST_TIME': u'1407551587', 
    u'REQUEST_URI': u'############', 
    u'SCRIPT_FILENAME': u'/var/www/PIAN/index.php', 
    u'SCRIPT_NAME': u'/index.php', 
    u'SCRIPT_URI': u'http://############/', 
    u'SCRIPT_URL': u'/############/', 
    u'SERVER_ADDR': u'############', 
    u'SERVER_ADMIN': u'[email protected]############', 
    u'SERVER_NAME': u'############', 
    u'SERVER_PORT': u'80', 
    u'SERVER_PROTOCOL': u'HTTP/1.1', 
    u'SERVER_SIGNATURE': u'<address>Apache/2.2.22 (Ubuntu) Server at ############ Port 80</address>\n', 
    u'SERVER_SOFTWARE': u'Apache/2.2.22 (Ubuntu)', 
    u'uniqID': u'bbc398716f4703cfabd761cc8d4101a1'}, 
    u'SESSION': {u'Entrance Time': 1407551587.7385, 
    u'uniqID': u'bbc398716f4703cfabd761cc8d4101a1'}}}, 
u'uniqID': u'bbc398716f4703cfabd761cc8d4101a1'} 

我使用Python軟件包elasticsearch.py​​作爲我的界面。我創建我的索引是這樣的:

es.indices.create(
    index=Visit_to_ElasticSearch.INDEX, 
    body={ 
     'settings': { 
      'number_of_shards': 5, 
      'number_of_replicas': 1, 
     } 
    }, 
    # ignore already existing index 
    ignore=400 
) 

這是我的映射:

# Create mappings of a visit 
time_date_mapping = { 'type': 'date_time' } 
str_not_analyzed = { 'type': 'string'} # This used to include 'index': 'not_analyzed' 

visit_mapping = { 
    'properties': { 
     'uniqID': str_not_analyzed, 
     'pages': str_not_analyzed, 
     'domain': str_not_analyzed, 
     'Srvr IP': str_not_analyzed, 
     'Visitor IP': str_not_analyzed, 
     'Agent': { 'type': 'string', 'index': 'not_analyzed' }, 
     'Referrer': { 'type': 'string' }, 
     'Entrance Time': time_date_mapping, 
     'Request Time': time_date_mapping, 
     'Raw': { 'type': 'string', 'index': 'not_analyzed' }, 
     'Pages': { 'type': 'string', 'index': 'not_analyzed' }, 
    }, 
} 

是ES報告的實際映射:

'visits': { 
    'mappings': { 
    'visit': { 
     'properties': { 
     'Agent': {'type': 'string'}, 
     'Entrance Time': {'format': 'dateOptionalTime', 'type': 'date'}, 
     'Pages': {'type': 'string'}, 
     'Raw': { 
      'properties': { 
      'Entrance Time': {'type': 'double'}, 
      'domain': {'type': 'string'}, 
      'uniqID': {'type': 'string'} 
      } 
     }, 
     'Referrer': {'type': 'string'}, 
     'Request Time': {'format': 'dateOptionalTime', 'type': 'date'}, 
     'Srvr IP': {'type': 'string'}, 
     'Visitor IP': {'type': 'string'}, 
     'domain': {'type': 'string'}, 
     'uniqID': {'type': 'string'} 
     } 
    } 
    } 
} 

當我甩我的試驗數據爲ES和在Kibana4中查看它有問題。從「發現」選項卡中,它會顯示前五個代理的「快速計數」,並顯示截斷版本的完整字符串。但是,當我使用聚合中的術語和字段中的Agetn創建可視化(Visualize->餅圖 - >從新搜索 - >分割片)時,我將前5列爲單個單詞列表 - 列表爲mozilla,5.0 ,兼容,http,2.0。

儘管我告訴它不要在映射中分析該字段,但Kibana警告我正在分析Agent字段。

我是這個品牌的新手,我假設如果代理沒有被分析,它會計算完整的代理字符串嗎?用下劃線替換空格並沒有解決這個問題。那麼我該如何解決這個問題?有沒有辦法讓代理商進入ES,以至於它只能作爲一個整體考慮?

謝謝

完全映射代碼可以在這個question找到。

-------捲曲後映射--------

我用curl --request PUT 'http://127.0.0.1:9200/visits/_mapping/visit?ignore_conflicts=true' --data '{"visit" : { "properties" : { "Agent" : { "type" : "string", "index" : "not_analyzed" } } } }'改變映射,這是新的映射:

{ 
    "visits" : { 
    "mappings" : { 
     "visit" : { 
     "properties" : { 
      "Agent" : { 
      "type" : "string", 
      "norms" : { 
       "enabled" : false 
      } 
      }, 
      "Entrance Time" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
      }, 
      "Pages" : { 
      "type" : "string" 
      }, 
      "Raw" : { 
      "properties" : { 
       "Entrance Time" : { 
       "type" : "double" 
       }, 
       "domain" : { 
       "type" : "string" 
       }, 
       "uniqID" : { 
       "type" : "string" 
       } 
      } 
      }, 
      "Referrer" : { 
      "type" : "string" 
      }, 
      "Request Time" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
      }, 
      "Srvr IP" : { 
      "type" : "string" 
      }, 
      "Visitor IP" : { 
      "type" : "string" 
      }, 
      "domain" : { 
      "type" : "string" 
      }, 
      "uniqID" : { 
      "type" : "string" 
      } 
     } 
     } 
    } 
    } 
} 
+0

你能告訴你如何將你的映射添加到你的索引中嗎?另外我會對'Visit_to_ElasticSearch.INDEX'背後的真實值感興趣。 – Val

回答

0

這是與this other issue相同的問題及其不起作用的原因與事實上visit_mapping從未通過put_mapping安裝。因此,ES根據visit文件中發送的內容創建了自己的映射。

爲了解決這個問題,之前只需撥打put_mapping與測繪索引你的第一visit文件。