added methods to update mappings
This commit is contained in:
parent
50b052a9bd
commit
2a39616379
1 changed files with 38 additions and 1 deletions
|
@ -10,9 +10,46 @@ class ElasticSearchHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_index
|
def create_index
|
||||||
|
header = { 'Content-type': 'application/json' }
|
||||||
response = RestClient::Request.execute(
|
response = RestClient::Request.execute(
|
||||||
method: :put,
|
method: :put,
|
||||||
url: "#{server_uri}/#{index}")
|
url: "#{server_uri}/#{index}",
|
||||||
|
header: header
|
||||||
|
payload: self.mappings.to_json)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mappings
|
||||||
|
{
|
||||||
|
"mappings": {
|
||||||
|
"_doc": {
|
||||||
|
"properties": {
|
||||||
|
"type": { "type": 'keyword' },
|
||||||
|
"paste_metadata": { "type": 'nested' },
|
||||||
|
"properties": [{
|
||||||
|
"scrape_url": { "type": 'string' },
|
||||||
|
"full_url": { "type": 'string' },
|
||||||
|
"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' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_mapping(mapping_json)
|
||||||
|
header = { 'Content-type': 'application/json' }
|
||||||
|
response = RestClient::Request.execute(
|
||||||
|
method: :put,
|
||||||
|
url: "#{server_uri}/#{index}/_mapping/#{doctype}",
|
||||||
|
payload: mapping_json,
|
||||||
|
headers: header)
|
||||||
end
|
end
|
||||||
|
|
||||||
def json_to_es(paste_json, method=nil)
|
def json_to_es(paste_json, method=nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue