Hi Please give me the indication./
I am using the elasticsearch 0.17.6 and couchdb 1.1.0
I have created two documents on couchdb:
Each document have the string fields: name, message. The first one is attached by a text file "test.txt" and the second one is not. The JSon code generated by CouchDB is like that:
{
"_id": "ID1",
"_rev": "6-e1ab4c5c65b98e9a0d91e5c8fc1629bb",
"name": "Document1",
"message": "Evaluate Elastic Search",
"_attachments": {
"test.txt": {
"content_type": "text/plain",
"revpos": 5,
"digest": "md5-REzvAVEZoSV69SLI/vaflQ==",
"length": 86,
"stub": true
}
}
}
{
"_id": "ID2",
"_rev": "2-72142ec18248cedb4dba67305d136aa8",
"name": "Document2",
"message": "test Elastic Search"
}
These two documents are in a database called my_test_couch_db
I have use Elasticsearch (ES) to index these documents using plugins: river and mapper-attachments. For each given text, I expect that ES can find, not only corresponding text in document's fields, but also in the attachment *.txt file. But it is impossible. I try many ways:I have created index manually, mapping (automatically and manually), configure river, etc. but ES can only find words in document's fields, it cannot find the ones in *.txt attachment files. I follow the indication of site http://www.elasticsearch.org but it doesnot work, either.
Thanks for your answers.
Here is my commands:
curl -X PUT "localhost:9200/test_idx_1"
curl -X PUT "localhost:9200/test_idx_1/test_mapping_1/_mapping" -d '{
"test_mapping_1": {
"properties": {
"_attachments": {
"type": "attachment",
"index": "yes"
}
}
}
}'
curl -XPUT 'http://localhost:9200/_river/test_river_1/_meta' -d '{
"type": "couchdb",
"couchdb": {
"host": "localhost",
"port": 5984,
"db": "my_test_couch_db",
"filter": null
},
"index": {
"index": "test_idx_1",
"type": "test_mapping_1"
}
}'
then, I try to search
curl -XPOST 'http://localhost:9200/my_test_couch_db/my_test_couch_db/_search'
(two documents are find very well )
curl -XPOST 'http://localhost:9200/my_test_couch_db/my_test_couch_db/_search' -d '{
"query": {
"text": {
"_all": "test"
}
}
}'
Here is the output
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.081366636,
"hits": [
{
"_index": "my_test_couch_db",
"_type": "my_test_couch_db",
"_id": "ID2",
"_score": 0.081366636,
"_source": {
"message": "test Elastic Search",
"_rev": "2-72142ec18248cedb4dba67305d136aa8",
"_id": "ID2",
"name": "Document2"
}
}
]
}
}
As you see, the ES can only find the word "test" in the message field, they cannot find this word in the *.text attachment files.
I try the other queries:
curl -XPOST 'http://localhost:9200/my_test_couch_db/my_test_couch_db/_search' -d '{
"query": {
"text": {
"_attachments": "test"
}
}
}'
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
curl -XPOST 'http://localhost:9200/my_test_couch_db/my_test_couch_db/_search' -d '{
"query": {
"text": {
"_attachments.fields.file": "test"
}
}
}'
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
The output is nothing. I try other mappings but it doesn't work, either.
Why is that and how to solve this problem?
Attachment are not yet loaded by couchDb river.
I have updated it but still waiting for users that it works fine.
See https://github.com/dadoonet/elasticsearch-river-couchdb/tree/attachments
You can try it here : https://github.com/downloads/dadoonet/elasticsearch-river-couchdb/elasticsearch-river-couchdb-1.2.0-SNAPSHOT.zip
If it works fine for you, I can create the pull request.
Related
As a marketer, I'm going through the EmailOctopus (email service provider) API docs (https://emailoctopus.com/api-documentation) and have trouble combining multiple requests in one.
Goal: Get all campaign reports for all campaigns exported to a CSV.
Step 1: Get all campaign IDs. This works.
curl GET https://emailoctopus.com/api/1.5/campaigns?api_key={APIKEY}
Step 2: Get the report for a single campaign. This works too.
curl GET https://emailoctopus.com/api/1.5/campaigns/{CAMPAIGNID}/reports/summary?api_key={APIKEY}
Step 3: Combine step 1 and 2 and export to a CSV. No idea how to proceed here.
Output step 1:
{
"data": [
{
"id": "00000000-0000-0000-0000-000000000000",
"status": "SENT",
"name": "Foo",
"subject": "Bar",
"to": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"from": {
"name": "John Doe",
"email_address": "john.doe#gmail.com"
},
"content": {
"html": "<html>Foo Bar<html>",
"plain_text": "Foo Bar"
},
"created_at": "2019-10-30T13:46:46+00:00",
"sent_at": "2019-10-31T13:46:46+00:00"
},
{
"id": "00000000-0000-0000-0000-000000000003",
"status": "SENT",
"name": "Bar",
"subject": "Foo",
"to": [
"00000000-0000-0000-0000-000000000004",
"00000000-0000-0000-0000-000000000005"
],
"from": {
"name": "Jane Doe",
"email_address": "jane.doe#gmail.com"
},
"content": {
"html": "<html>Bar Foo<html>",
"plain_text": "Bar Foo"
},
"created_at": "2019-11-01T13:46:46+00:00",
"sent_at": "2019-11-02T13:46:46+00:00"
}
],
"paging": {
"next": null,
"previous": null
}
}
Output step 2:
{
"id": "00000000-0000-0000-0000-000000000000",
"sent": 200,
"bounced": {
"soft": 10,
"hard": 5
},
"opened": {
"total": 110,
"unique": 85
},
"clicked": {
"total": 70,
"unique": 65
},
"complained": 50,
"unsubscribed": 25
}
How can I get all campaign reports in one go and exported to a CSV?
May be this URLs be helpful
Merging two json in PHP
How to export to csv file a PHP Array with a button?
https://www.kodingmadesimple.com/2016/12/convert-json-to-csv-php.html
I am following this example https://www.compose.com/articles/how-to-script-painless-ly-in-elasticsearch/
where BOTH the ORIGINAL fields plus the calculated field (some_scores) are presented in the result document.
{
"_index": "sat",
"_type": "scores",
"_id": "AV3CYR8JFgEfgdUCQSON",
"_score": 1,
"_source": {
"cds": 1611760130062,
"rtype": "S",
"sname": "American High",
"dname": "Fremont Unified",
"cname": "Alameda",
"enroll12": 444,
"NumTstTakr": 298,
"AvgScrRead": 576,
"AvgScrMath": 610,
"AvgScrWrit": 576,
"NumGE1500": 229,
"PctGE1500": 76.85,
"year": 1516
},
"fields": {
"some_scores": [
1152
]
}
}
Now i am doing a _search with the following post body
{
"query": {
"match_all": {}
},
"script_fields": {
"some_scores": {
"script": {
"lang": "painless",
"inline": "\"hello\""
}
}
}
}
but the results i am getting DOESN'T contain the original fields; it only contains the testing field which i hardcoded to hello. Is there anything wrong with my query ?
"hits": [
{
"_index": "abcIndex",
"_type": "data",
"_id": "id_00000025",
"_score": 1.0,
"fields": {
"some_scores": [
"hello"
]
}
}]
You need to explicitly pass _source": ["*"] when using script field.
I was not able to find reason for this , looks like some kind of optimization.
{
"_source": ["*"],
"query": {
"match_all": {}
},
"script_fields": {
"some_scores": {
"script": {
"lang": "painless",
"inline": "doc['authorization']+\"hello\""
}
}
}
I have an internal app that uses a webhook listener and some scripting to manipulate the input data. I'm posting this to it:
curl -X POST -d '{
"assignment_id": 12345,
"updated_custom_fields": [{
"name": "RNVIDAYEBB",
"value": "updated!"
},
{
"name": "QUFTXSIBYA",
"value": "and me too"
}
],
"custom_fields": [{
"id": 981,
"name": "RDEXDPVKRD",
"fields": [
{
"id": 4096,
"name": "RNVIDAYEBB",
"default": "EDJEAJICYW",
"required": true,
"value": "Blah"
},
{
"id": 4097,
"name": "QUFTXSIBYA",
"default": "",
"required": true,
"value": ""
}]
}]
}' "https://hooks.zapier.com/hooks/catch/......"
My script is as follows:
update_custom_fields_by_name_pre_write: function(bundle) {
var updatedFields = _.map(bundle.request.data.custom_fields, function(group) {
return _.map(group.fields, function(field) {
return _.extend(field, _.findWhere(bundle.request.data.updated_custom_fields, { name: field.name} ));
});
});
bundle.request.data = updatedFields;
return bundle.request;
}
I know that the merging logic is good, but it appears that the custom_fields and updated_custom_fields arrays are not present in the bundle.request.data object. Anyone know how to get access to them in the script?
It seems like you should be using update_custom_fields_by_name_catch_hook to capture the incoming static webhook data (instead of _pre_write). If you use that, you can capture the data within bundle.cleaned_request.custom_fields and bundle.cleaned_request.updated_custom_fields.
I have an index named books which has reviews as an object which can handle arrays.
While retrieving data, in a particular case I only want the review having maximum rating.
"books" :{
"reviews": {
"properties": {
"rating": {
"type": "float"
},
"comments": {
"type": "string"
}
}
},
"author" : {
"type" : "string"
}
}
Many books can have many reviews each having some rating. For a particular use case I only want the result set to have the reviews having maximum rating. I need to build a search query for that kind of result.
POST books/_search
{
"size": 51,
"sort": [
{
"reviews.rating": {
"order": "asc",
"mode" : "min"
}
}
],
"fields": [
"reviews","author"]
}
By using script_fields one can build dynamic fields but not objects. Else I could have made a dynamic object reviews having one field as rating and another as comment.
script_fields can be used to build both dynamic fields and objects:
curl -XDELETE localhost:9200/test-idx
curl -XPUT localhost:9200/test-idx -d '{
"mappings": {
"books" :{
"reviews": {
"properties": {
"rating": {
"type": "float"
},
"comments": {
"type": "string"
}
}
},
"author" : {
"type" : "string"
}
}
}
}'
curl -XPOST "localhost:9200/test-idx/books?refresh=true" -d '{
"reviews": [{
"rating": 5.5,
"comments": "So-so"
}, {
"rating": 9.8,
"comments": "Awesome"
}, {
"rating": 1.2,
"comments": "Awful"
}],
"author": "Roversial, Cont"
}'
curl "localhost:9200/test-idx/books/_search?pretty" -d '{
"fields": ["author"],
"script_fields": {
"highest_review": {
"script": "max_rating = 0.0; max_review = null; for(review : _source[\"reviews\"]) { if (review.rating > max_rating) { max_review = review; max_rating = review.rating;}} max_review"
}
}
}'
I'm planning to use the Built-in Like for mobile users, and the standard Like Button for web users to "like" a webpage.
But is the Built-in Like feature has a connection to the Like Button (Social Plugin)?
From my observation:
On web version, after I clicked the standard Like Button, the Open Graph Object can track that like instantly
Calling fql?q=SELECT share_count, like_count, comment_count, total_count, click_count FROM link_stat WHERE url="http://websitelinkhere.com";
returns
{
"data": [
{
"share_count": 0,
"like_count": 1,
"comment_count": 0,
"total_count": 1,
"click_count": 0
}
]
}
But using the Built-in Like, the Open Graph Object cannot track that 'like' at all, the like_count and total_count are both 0.
And then here's the funny part:
By checking my og.likes using https://graph.facebook.com/userid/og.likes?access_token=myAccessToken
It returns TWO likes, 1 from the Like Button and 1 from the Built-in Like Action
{
"data": [
{
"id": "10151050736776633",
"from": {
//skipped
},
"start_time": "2012-08-24T07:10:52+0000",
"end_time": "2012-08-24T07:10:52+0000",
"publish_time": "2012-08-24T07:10:52+0000",
"application": {
//skipped
},
"data": {
//skipped
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true
}
},
{
"id": "10151050736586633",
"from": {
//skipped
},
"start_time": "2012-08-24T07:10:42+0000",
"publish_time": "2012-08-24T07:10:42+0000",
"application": {
//skipped
},
"data": {
//skipped
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true
}
}
]
}
And then by using action id returned by og.likes, I can delete both likes using
curl -X DELETE \
-F 'access_token=accessToken' \
https://graph.facebook.com/10151050736776633
and
curl -X DELETE \
-F 'access_token=accessToken' \
https://graph.facebook.com/10151050736586633
Is it because I haven't submit my application to Facebook for reviewing yet?
I'm expecting the Built-in Like and Like Button work together as ONE action, but not generating og.likes independently.
Thank you for your time.
Adding og:url and using the Open Graph Object ID directly fixes the problem.
curl -X POST \
-F 'access_token=accessTokenHere' \
-F 'object=UsingOpenGraphObjectIDHereDirectly' \
https://graph.facebook.com/useridhere/og.likes
May be related to Impossibile to publish built-in Like action on Open Graph Pages with Likes