I am working on a existing rails app, where they are currently using elasticsearch gem. Now I am trying to switch it to searchkick. I have configured the gem on the app.
Currently if I do :
Model.search(keyword) from the console, I am getting the out put.
But currently they are passing query string as a nested hash in the actual application, which looks like follows:
{:query=>{:bool=>{:must=>[{:multi_match=>{:query=>"apple", :fields=>["title^2", "content", "description"]}}], :should=>[], :filter=>[{:term=>{:data_proxy_id=>"4d629f00-c8b1-aacc-97b5-e21e4c0bbe3f"}}, {:term=>{:article_type=>"Article"}}, {:term=>{:status=>"published"}}]}}, :sort=>{"_score"=>{"order"=>"desc"}}, :aggs=>{:group_by_section=>{:terms=>{:field=>"section.name.raw", :size=>0}}, :group_by_category=>{:terms=>{:field=>"category.name.raw", :size=>0}}, :group_by_author=>{:terms=>{:field=>"authors.fullname.raw", :size=>0}}, :year_based=>{:date_histogram=>{:field=>"publish_date", :interval=>"1y", :format=>"yyyy", :min_doc_count=>1, :time_zone=>"+00:00"}}, :month_year_based=>{:date_histogram=>{:field=>"publish_date", :interval=>"month", :format=>"MM-yyy", :min_doc_count=>1, :time_zone=>"+00:00"}}}}
If I pass this hash as the params to Model.search(query_hash). I am getting the following error.
ArgumentError: unknown keywords: query, sort
Try with
Model.search body: {:query=>{:bool=>{:must=>[{:multi_match=>{:query=>"apple", :fields=>["title^2", "content", "description"]}}], :should=>[], :filter=>[{:term=>{:data_proxy_id=>"4d629f00-c8b1-aacc-97b5-e21e4c0bbe3f"}}, {:term=>{:article_type=>"Article"}}, {:term=>{:status=>"published"}}]}}, :sort=>{"_score"=>{"order"=>"desc"}}, :aggs=>{:group_by_section=>{:terms=>{:field=>"section.name.raw", :size=>0}}, :group_by_category=>{:terms=>{:field=>"category.name.raw", :size=>0}}, :group_by_author=>{:terms=>{:field=>"authors.fullname.raw", :size=>0}}, :year_based=>{:date_histogram=>{:field=>"publish_date", :interval=>"1y", :format=>"yyyy", :min_doc_count=>1, :time_zone=>"+00:00"}}, :month_year_based=>{:date_histogram=>{:field=>"publish_date", :interval=>"month", :format=>"MM-yyy", :min_doc_count=>1, :time_zone=>"+00:00"}}}}
Related
I am receiving JSON from a http terraform data source
data "http" "example" {
url = "${var.cloudwatch_endpoint}/api/v0/components"
# Optional request headers
request_headers {
"Accept" = "application/json"
"X-Api-Key" = "${var.api_key}"
}
}
It outputs the following.
http = [{"componentID":"k8QEbeuHdDnU","name":"Jenkins","description":"","status":"Partial Outage","order":1553796836},{"componentID":"ui","name":"ui","description":"","status":"Operational","order":1554483781},{"componentID":"auth","name":"auth","description":"","status":"Operational","order":1554483781},{"componentID":"elig","name":"elig","description":"","status":"Operational","order":1554483781},{"componentID":"kong","name":"kong","description":"","status":"Operational","order":1554483781}]
which is a string in terraform. In order to convert this string into JSON I pass it to an external data source which is a simple ruby function. Here is the terraform to pass it.
data "external" "component_ids" {
program = ["ruby", "./fetchComponent.rb",]
query = {
data = "${data.http.example.body}"
}
}
Here is the ruby function
#!/usr/bin/env ruby
require 'json'
data = JSON.parse(STDIN.read)
results = data.to_json
STDOUT.write results
All of this works. The external data outputs the following (It appears the same as the http output) but according to terraform docs this should be a map
external1 = {
data = [{"componentID":"k8QEbeuHdDnU","name":"Jenkins","description":"","status":"Partial Outage","order":1553796836},{"componentID":"ui","name":"ui","description":"","status":"Operational","order":1554483781},{"componentID":"auth","name":"auth","description":"","status":"Operational","order":1554483781},{"componentID":"elig","name":"elig","description":"","status":"Operational","order":1554483781},{"componentID":"kong","name":"kong","description":"","status":"Operational","order":1554483781}]
}
I was expecting that I could now access data inside of the external data source. I am unable.
Ultimately what I want to do is create a list of the componentID variables which are located within the external data source.
Some things I have tried
* output.external: key "0" does not exist in map data.external.component_ids.result in:
${data.external.component_ids.result[0]}
* output.external: At column 3, line 1: element: argument 1 should be type list, got type string in:
${element(data.external.component_ids.result["componentID"],0)}
* output.external: key "componentID" does not exist in map data.external.component_ids.result in:
${data.external.component_ids.result["componentID"]}
ternal: lookup: lookup failed to find 'componentID' in:
${lookup(data.external.component_ids.*.result[0], "componentID")}
I appreciate the help.
can't test with the variable cloudwatch_endpoint, so I have to think about the solution.
Terraform can't decode json directly before 0.11.x. But there is a workaround to work on nested lists.
Your ruby need be adjusted to make output as variable http below, then you should be fine to get what you need.
$ cat main.tf
variable "http" {
type = "list"
default = [{componentID = "k8QEbeuHdDnU", name = "Jenkins"}]
}
output "http" {
value = "${lookup(var.http[0], "componentID")}"
}
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
http = k8QEbeuHdDnU
When having a look to my couchbase view using the web api I got this result:
{
"total_rows": 18279385,
"rows": []
}
But I'm using the ruby couchbase gem like follows
require 'couchbase'
c = Couchbase.connect(...)
sources = c.design_docs['Data']
pp sources.All
#<Couchbase::View:47373151271840 #endpoint="_design/Data/_view/All" #params={:connection_timeout=>75000}>
But how do I get the total_rows from the view? I've found few documentation which relates to a Method "total_rows" but that doesn't seem to be present at this point.
The comment of Anthony solves the problem:
sources.All(limit: 0).fetch.total_rows
Use limit: 0 for speeding up the request.
I have some data in a Custom Screen in Zabbix, and would like to pull the data from the screen via the API. I'm using this Ruby gem: https://github.com/express42/zabbixapi
I'm able to successfully connect and query, but the results I'm getting are not very useful:
p zbx.query(
:method => "item.get",
:params => {
:itemids => "66666",
:output => "extend"
}
)
# [{"itemid"=>"66666", "type"=>"0", "snmp_community"=>"", "snmp_oid"=>"", "hostid"=>"77777", "name"=>"Fro Packages", "key_"=>"system.sw.packages[davekey1|davekey2|davekey3|davekey4]", "delay"=>"300", "history"=>"90", "trends"=>"365", "status"=>"0", "value_type"=>"1", "trapper_hosts"=>"", "units"=>"", "multiplier"=>"0", "delta"=>"0", "snmpv3_securityname"=>"", "snmpv3_securitylevel"=>"0", "snmpv3_authpassphrase"=>"", "snmpv3_privpassphrase"=>"", "formula"=>"1", "error"=>"", "lastlogsize"=>"0", "logtimefmt"=>"", "templateid"=>"88888", "valuemapid"=>"0", "delay_flex"=>"", "params"=>"", "ipmi_sensor"=>"", "data_type"=>"0", "authtype"=>"0", "username"=>"", "password"=>"", "publickey"=>"", "privatekey"=>"", "mtime"=>"0", "flags"=>"0", "filter"=>"", "interfaceid"=>"25", "port"=>"", "description"=>"", "inventory_link"=>"0", "lifetime"=>"30", "snmpv3_authprotocol"=>"0", "snmpv3_privprotocol"=>"0", "state"=>"0", "snmpv3_contextname"=>""}]
You can see that it's returning a bunch of ID's for the items, including the correct keys, but I can't seem to get the actual plain text values, which is the data I'm interested in.
I started with the screen_id, then got the screenitem_id, now the item_id, but I don't seem to be getting any closer to what I want!
Thanks for any help
Getting items or getting hosts means getting their description, not the data. is You are after history. Reading the actual Zabbix user manual and API docs is highly recommended.
I'm trying to use a geo_point field on Heroku/Bonsai but it just doesn't want to work.
It works in local, but whenever I check the mapping for my index on Heroku/Bonsai it says my field is a string: "coordinates":{"type":"string"}
My mapping looks like this:
tire.mapping do
...
indexes :coordinates, type: "geo_point", lat_lon: true
...
end
And my to_indexed_json like this:
def to_indexed_json
{
...
coordinates: map_marker.nil? ? nil : [map_marker.latitude, map_marker.longitude].join(','),
...
}.to_json
end
In the console on Heroku I tried MyModel.mapping and MyModel.index.mapping and the first one correctly has :coordinates=>{:type=>"geo_point", :lat_lon=>true}.
Here's how I got this to work. Index name 'myindex' type name 'myindextype'
On the local machine
curl -XGET https://[LOCAL_ES_URL]/myindex/myindextype/_mapping
save the output to a .json file. example: typedefinition.json (or hand build one)
{
"myindextype":{
"properties":{
"dataone":{"type":"string"},
"datatwo":{"type":"double"},
"location":{"type":"geo_point"},
"datathree":{"type":"long"},
"datafour":{"type":"string"}
}
}
}
On heroku enter the command
heroku config
and get the BONSAI_URL. Put it in the follwoing commands in place of [BONSAI_URL]. (https://asdfasdfdsf:asdfadf#asdfasdfasdf.us-east-1.bonsai.io/myindex)
curl -XDELETE https://[BONSAI_URL]/myindex
curl -XPOST https://[BONSAI_URL]/myindex
curl -XPUT -d#typedefinition.json https://[BONSAI_URL]/myindex/myindextype/_mapping
curl -XGET https://[BONSAI_URL]/myindex/myindextype/_mapping
Deletes the indes if it exists.
Createds an empty index.
Uses the .json file as a definition for mapping.
Get the new mapping to make sure it worked.
i have reduced this to as little as possible but wondering what i am doing wrong with this little ruby file:
params ={'title'=>'qwert', 'fulltext'=>'qwert', 'user_twitter_id'=>'qwert'}
res = Net::HTTP.post_form(URI.parse('http://127.0.0.1:3000/details/'), params)
puts res.body
This does result in a record being created but none of the params being inserted, yet they seem recognised?
Started POST "/details/" for 127.0.0.1 at 2011-10-31 12:37:02 +0000
Processing by DetailsController#create as
Parameters: {"title"=>"qwert", "fulltext"=>"qwert", "user_twitter_id"=>"qwert"}
AREL (0.3ms) INSERT INTO "details" ("title", "fulltext", "user_twitter_id", "created_at", "updated_at") VALUES (NULL, NULL, NULL, '2011-10-31 12:37:02.401881', '2011- 10-31 12:37:02.401881')
Redirected to http://127.0.0.1:3000/details/23
Completed 302 Found in 185ms
In standard Rails you need a root element (you don't show the controller action, so I must assume):
params = {:detail => {...}}
BTW, a higher-level library as rest-client may come handy ([edit] Marian notes that nested hashes are not managed by Net::HTTP, so try rest-client)