made a mapping that worked and some more stuff to the elastic search helper

This commit is contained in:
booboy 2019-02-01 23:49:35 -06:00
parent 2a39616379
commit ee93b17576
3 changed files with 22 additions and 27 deletions

View file

@ -14,29 +14,21 @@ class ElasticSearchHelper
response = RestClient::Request.execute( response = RestClient::Request.execute(
method: :put, method: :put,
url: "#{server_uri}/#{index}", url: "#{server_uri}/#{index}",
header: header headers: header,
payload: self.mappings.to_json) payload: self.mappings.to_json)
end end
def mappings def mappings
{ {
"mappings": { "mappings": {
"_doc": { "_doc": {
"properties": { "properties": {
"type": { "type": 'keyword' }, "paste_metadata": {
"paste_metadata": { "type": 'nested' }, "type": "nested"
"properties": [{ },
"scrape_url": { "type": 'string' }, "paste_text": {
"full_url": { "type": 'string' }, "type": "text"
"date": { "type": 'string' }, }
"size": { "type": 'string' },
"expire": { "type": 'string' },
"title": { "type": 'string' },
"syntax": { "type": 'string' },
"user": { "type": 'string' },
"hits": { "type": 'string' }
}],
"paste_text": { "type": 'string' }
} }
} }
} }
@ -63,7 +55,7 @@ class ElasticSearchHelper
def json_to_es_bulk(array_of_paste_json) def json_to_es_bulk(array_of_paste_json)
array_of_paste_json.each do |paste_json| array_of_paste_json.each do |paste_json|
self.to_es(paste_json) self.json_to_es(paste_json)
end end
end end

View file

@ -1,9 +0,0 @@
require 'elasticsearch'
client = Elasticsearch::Client.new url: 'http://192.168.1.9200', log: true
client.transport.reload_connections!
client.cluster.health
client.index index: 'paste', type: 'pastes'

12
lib/mappings.json Normal file
View file

@ -0,0 +1,12 @@
{
"mappings": {
"_doc": {
"properties": {
"paste_metadata": {
"type": "nested"
},
"paste_text": { "type": "text" }
}
}
}
}