kibana histogram value field use string? - kibana

i have a task..
the Values field of the Histogram must be contain a numeric value
but.. my value field come from string ,like this
traceMsg: api_name=xxx&pageSize=20
and i need the 20 as value field..
{
"_index": "tracelog",
"_type": "tracelog",
"_id": "TS7s-gkUSsiH7gqnkHOjpA",
"_score": null,
"_source": {
"id": null,
"host": "10.153.192.105",
"appId": "32",
"spanIndex": 1,
"spanLevel": 1,
"spanFlag": 0,
"spanId": "1",
"parentSpanId": "0",
"taobaoId": 1659018141,
"traceId": "e7e2e60a6ade4f4ab23df4994b2392ae",
"traceLoc": "http",
"traceType": 0,
"traceUrl": "/trade/search",
"traceMsg": "api_name=trade_search&queryId=1&sys=true&timeType=created&field=created&order=asc&pageNo=1&pageSize=20",
"payTime": 1173,
"logTime": "2014-11-13T16:16:43+0800"
},
"sort": [
1415866603000
]
}
i don't know how to do. :)

This is what logstash is for. Check out the grok filter, which would let you parse the traceMsg field and make your own field for the pageSize value.

How do you insert data on elasticsearch without using logstash? You can use the mutate filter to change the field type.

Related

Does SmartSheet support any CURL to get the total row count in a sheet?

I am using curl with REST to access Smartshets in my C# running on WIN CE. My application is supposed to dump some data on smartsheet periodically.
Before I write to a sheet, I would like to know the total row count in the sheet so that I don't exceed 5000 rows per sheet.
I am looking for an API that would return just row count given the sheet id?
Currently using below API which returns the entire sheet data and takes very long to fetch and format.
curl https://api.smartsheet.com/2.0/sheets/{sheetId}
with data of upto 5000 rows pr sheet, it takes very long to fetch and format below response to determine the available rows:
{
"id": 4583173393803140,
"name": "sheet 1",
"version": 6,
"totalRowCount": 240,
"accessLevel": "OWNER",
"effectiveAttachmentOptions": [
"EVERNOTE",
"GOOGLE_DRIVE",
"EGNYTE",
"FILE",
"ONEDRIVE",
"DROPBOX",
"BOX_COM"
],
"readOnly": true,
"ganttEnabled": true,
"dependenciesEnabled": true,
"resourceManagementEnabled": true,
"cellImageUploadEnabled": true,
"userSettings": {
"criticalPathEnabled": false,
"displaySummaryTasks": true
},
"userPermissions": {
"summaryPermissions": "ADMIN"
},
"workspace": {
"id": 825898975642500,
"name": "New Workspace"
},
"projectSettings": {
"workingDays": [
"MONDAY",
"TUESDAY",
"WEDNESDAY"
],
"nonWorkingDays": [],
"lengthOfDay": 8
},
"hasSummaryFields": false,
"permalink": "https://app.smartsheet.com/b/home?lx=pWNSDH9itjBXxBzFmyf-5w",
"createdAt": "2018-09-24T20:27:57Z",
"modifiedAt": "2018-09-26T20:45:08Z",
"columns": [
{
"id": 4583173393803140,
"version": 0,
"index": 0,
"primary": true,
"title": "Primary Column",
"type": "TEXT_NUMBER",
"validation": false
},
{
"id": 2331373580117892,
"version": 0,
"index": 1,
"options": [
"new",
"in progress",
"completed"
],
"title": "status",
"type": "PICKLIST",
"validation": true
}
],
"rows": Array[4962]....
}
Any help will b greatly appreciated.enter code here
There isn't a request to specifically return the number of rows on a Sheet. But, with any GET /sheets/{sheetId} operation the resulting Sheet object returned will have a top level totalRowCount attribute on it. So, you don't have to GET the sheet and count the objects in the rows array. Instead you can look to the totalRowCount attribute and the value there to know how many rows are currently on the sheet.
If you are concerned about pulling down all of the Sheet data you can use paging to keep from getting all of the data returned. Doing a GET /sheets/{sheetId}?pageSize=1 will give you the Sheet object with only the first row of data to help make the payload smaller. The totalRowCount attribute will still be present in the response.

WooCommerce REST API: updating order line item metadata for shipment

I've stubled upon an issue for updating order line items' metadata via WooCommerce REST API using node.js.
I've been following these steps for updating orders (and was succesful with some fields):
https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order
Now, what I would like to achieve is changing the number of shipped line items of an order. Something I would normally use the partial orders WC plugin in the wordpress UI.
Below, you can find a screenshot of a line item I get from WC using the orders API call. The last element of the meta_data array has key 'shipped' and it contains an array with one object, stating that one (out of two ordered items) had been shipped:
"line_items": [{
"id": 1937,
"name": "Maya",
"product_id": 1271,
"variation_id": 1272,
"quantity": 2,
"tax_class": "",
"subtotal": "140.00",
"subtotal_tax": "0.00",
"total": "140.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": [{
"id": 21637,
"key": "pa_product-color",
"value": "beige"
}, {
"id": 21638,
"key": "pa_shoe-size",
"value": "42"
}, {
"id": 21639,
"key": "pa_shoe-width",
"value": "wide"
}, {
"id": 21640,
"key": "shipped",
"value": [{
"qty": 1,
"date": "Nov 21, 2017"
}
]
}
],
"sku": "2522BE42W",
"price": 70
},
As you can see, the value of the key 'shipped' is an object. When I ty to send it (back) to WC, I get an error saying:
"data":{"status":400,"params":{"line_items":"line_items[0][meta_data][3][value] is not of type string."}}}
When I try to send the value as a string, i.e.
lineItems[0].meta_data = [{key:"shipped", value: "[{qty:'2'}]" }]
I get no errors, but WC treats this as string, not as an object and doesn't update the shipment qty in the DB the way I intended (it only pulls the shipped quantity down to 0 instead):
{
"id": 21640,
"key": "shipped",
"value": "[{qty:'2'}]"
}
Any insights or ideas - how could I modify the shipped quantity of line items via the WC API?
So, apparently there was a bug in WP 4.9 version, which was fixed recently in the following commit:
https://github.com/woocommerce/woocommerce/pull/17849
It concerns REST API schema and after merging the fix to WooCommerce, the problems disappear and now I am able to send the data as an object.
More on the topic can be found here:
https://github.com/woocommerce/wc-api-dev/pull/74

Elasticsearch - foselastica Sorting by integer having strange results

i want to sort my result of companies based on the count of nested (employment)objects,
i added an extra field to the company entity that holds the count like:
private employeeCount;
getEmployeeCount(){
return count($this->employments);
}
and added it to the index like:
company:
mappings:
fullname: ~
employeeCount: ~
the field is correctly indexed and i get hits like:
"_hit": {
"_index": "search",
"_type": "company",
"_id": "2628",
"_source": {
"fullname": "acme",
"employeeCount": 9,
... },
"sort": [
"9"
]
i added the sort like:
$query->addSort(array('employeeCount' => array( 'order'=>'desc')));
and the result seems to be sorted correctly down from " 9, 8, 7, 6 ...",
but for some reason there are some results somewhere in the middle with higher employeeCount
for example this:
"_hit": {
"_index": "search",
"_type": "company",
"_id": "2668",
"_source": {
"fullname": "acme2",
"employeeCount": 18,
... },
"sort": [
"18"
]
i expect this result to be on top of my first example but it is somewhere between 2 and 1
so two guesses, it is sorting from 0-10 and everything greater than 10 is ignored
or there is some bug in elasticsearch or foselastica bundle,
heres the resulting query:
search/company/_search (GET) 5.59 ms {"sort":[{"employeeCount":{"order":"desc"}}],"query":{"wildcard":{"fullname":{"value":"**","boost":1}}},"size":"2000","from":0}
anybody any idea ?
Seems like it is sorting as a string instead of an integer. You can add a type to the sort params to specify integer.

MQL Query Help Required: Getting aliases of episodes from a season MID

I am trying to capture 351 and their aliases of season - "/m/07mx74h", but when I am using my query it gives only not-null values, while I also need those records which are null. PFA query and let me know how can I get all results for 351 records.
Thanks in advance!
MQL Query:
[{
"id": "/m/07mx74h",
"/tv/tv_series_season/episodes": [{
"limit": 1000,
"mid": null,
"name": null,
"/common/topic/alias": [{
"value": null
}]
}]
}]
I'm not sure I completely understand your question, but if the goal is to also include episodes which don't have an alias, you can use this:
[{
"id": "/m/07mx74h",
"/tv/tv_series_season/episodes": [{
"limit": 1000,
"mid": null,
"name": null,
"/common/topic/alias": []
}]
}]
The inner text value is the default returned, so you don't need the inner curly braces.

Freebase: Get name & Wikipedia ID in one query in a certain language

Is it possible to do one query in MQL to obtain the name and the wikipedia ID for a certain language from Freebase? If that's possible, is it also possible to do this for a set of languages (eg. german & english)?
Asked and answered, but here's a slightly better form of the query:
[{
"id": "/en/white_house",
"mid": null,
"de:name": {
"lang": "/lang/de",
"value": null
},
"en:name": null,
"wiki_de:key": {
"/type/key/namespace": "/wikipedia/de_id",
"value": null,
"optional": True,
},
"wiki_en:key": {
"/type/key/namespace": "/wikipedia/en_id",
"value": null,
"optional": True,
}
}]​
The Wikipedia keys will be escaped if they contain special characters, so you should consult
http://wiki.freebase.com/wiki/MQL_key_escaping for how to unescape them.
Some of the reasons this query is better include:
English is the default language, so it doesn't need to be specified for names
it removes the ambiguity of the namespace lookup. Your original query is actually looking for the key "white_house" in any namespace (and finding it in "/en" which is equivalent to the id "/en/white_house")
Note that you don't need to do the lookup by ID. You can use any lookup facility that MQL provides such as looking up by one of the Wikipedia keys or using "name~=":"white house" to find all topics containing that string or anything else that works for your starting data and your use case.
After playing around with MQL I finally came up with the following query (for white_house):
[{
"id": null,
"mid": null,
"de:name": {
"lang": "/lang/de",
"value": null
},
"en:name": {
"lang": "/lang/en",
"value": null
},
"key": {
"value": "white_house"
},
"wiki_de:key": {
"/type/key/namespace": "/wikipedia/de_id",
"value": null
},
"wiki_en:key": {
"/type/key/namespace": "/wikipedia/en_id",
"value": null
}
}]

Resources