Elastic search bulk index with C# API - c#

I want to bulk index json records to elastic search with NEST or Elasticsearch.Net API
My json data is :
{"index":{"_index":"abc","_type":"abc","_id":1}},{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"chrome","CPU":142.9375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":3336.34375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":7.1875,"Company":null,"Product":null,"Path":null}\n\n
my code:
var connectionSettings = new ConnectionSettings(new
Uri("http://localhost:9200/"));
var client2 = new ElasticClient(connectionSettings);
var jsonPostData = new PostData<object>(myJson);
var bulkRequestParameters = new BulkRequestParameters
{
};
Func<BulkRequestParameters, BulkRequestParameters> convert = delegate
(BulkRequestParameters s)
{
s.ErrorTrace(true);
return s.Refresh(Refresh.True);
};
var response = client2.LowLevel.Bulk<VoidResponse>("abc", "abc",
jsonPostData, convert);
In the response elastic return success with no error but still, data is not available on elastic?
Debug info from elastic:Successful low level call on POST: /abc/abc/_bulk?error_trace=true&refresh=true
It would be very helpful if someone can provide any clue what I am doing wrong here?

Solved this by modifying input JSON format after each record-set it does not requires comma:
{"index":{"_index":"abc","_type":"abc","_id":1}}{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"audiodg","CPU":1.5625,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":144.109375,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":3384.609375,"Company":null,"Product":null,"Path":null}

Related

INVALID_REQUEST_BODY Error calling ListStatusAsync using C# DocuSign SDK

I am using C# DocuSign SDK. I am simply trying to retrieve Envelopes, so using EnvelopesApi.ListStatusAsync. Like this:
EnvelopesApi envelopeApi = new EnvelopesApi(ApiClient.Configuration);
var options = new ListStatusOptions();
var date = DateTime.Now.AddDays(-30);
options.fromDate = date.ToString("yyyy/MM/dd");
var envelopesList = envelopeApi.ListStatusAsync(AccountId, null, options);
Response:
Error calling ListStatus:
{
"errorCode": "INVALID_REQUEST_BODY",
"message": "The request body is missing or improperly formatted."
}
Fiddler shows a 400. I can see Access Token is included in the request (Bearer Authorization Header), so no issues there. Fiddler shows PUT request:
https://demo.docusign.net/restapi/v2.1/accounts/[Account_ID_Guid]/envelopes/status?from_date=2019%2f12%2f14
Basically, this is code retrieved from: https://github.com/docusign/qs-csharp. Only difference is using ListStatusAsync instead of ListStatus. Am I missing something related to Body?
Your code doesn't quite match what the QuickStart example does. In the QS, the method used is ListStatusChanges, not ListStatus.
Try this to get a list of envelopes from the past 30 days:
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
var options = new EnvelopesApi.ListStatusChangesOptions();
var date = DateTime.Now.AddDays(-30);
options.fromDate = date.ToString("yyyy/MM/dd");
var envelopesList = envelopesApi.ListStatusChanges(accountId, options);
var envelopesListFromAsync = envelopesApi.ListStatusChangesAsync(accountId, options);

Netcore Elasticsearch (NEST) DefaultIndex is UriEncoded

Trying to get a basic Elasticsearch Count to work in my netcore API.
Following the documentation I believe this should work-
var node = new Uri(host);
var settings = new ConnectionSettings(node);
settings.DefaultIndex("foo/bar");
var client = new ElasticClient(settings);
var x = await client.CountAsync<dynamic>();
return x.Count;
There is a problem with this, however. The DefaultIndex is encoding slashes (/foo%2Fbar/object/_count). I'm getting a no_index_found_exception exception.
It seems like an easy problem to fix, but I can't find the documentation for this.
How do I prevent uri encoding on my DefaultIndex?
To specify multiple indices as the default index, separate them with a comma. NEST will URI encode the comma
var defaultIndex = "users,posts";
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.DefaultIndex(defaultIndex)
.DefaultTypeName("doc");
var client = new ElasticClient(settings);
var searchResponse = client.Search<object>(s => s);
Will send a search request to
POST http://localhost:9200/users%2Cposts/doc/_search

Bad Request: QUERY_ID_INVALID telegram bot api

I Want use telegram api bot . every thing is ok (in my idea) but i have stupid error that where ever is search i cant find any thing .
I am using Inline mode .
var awnser = new AnswerInlineQuery()
{
inline_query_id =model.inline_query.id,
results = new List<InlineQueryResultArticle>()
};
awnser.results.Add(new InlineQueryResultArticle() { id = Guid.NewGuid().ToString("N"), type = "article", url = "fidilio", input_message_content = new InputTextMessageContent() { message_text = "salam" }, title = "test" });
var send = SendInlineAwnser(awnser);
The send method is using restsharp
var ser = JsonConvert.SerializeObject(data);
var url = "https://api.telegram.org/bot" + telegramToken + "/answerInlineQuery";
var req = SimplePost<AnswerInlineQuery>(ser, url);
my serlization out put is this
{"inline_query_id":"302418856930797437","results":[{"type":"article","id":"fae56651b23244f8a3be94b1e6ebf6e7","title":"test","input_message_content":{"message_text":"salam"},"url":"fidilio"}]}
make sure that model.inline_query.id is correct and if so, keep in mind that you can send notify max 15 sec after inline keyboard pushed. Besides, I suggest using async method for sending inline query results.

ElasticSearch Index/Insert with NEST fail

I'm trying to insert some JSON data into elastic search for testing.
here is the code:
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
settings.DefaultIndex("FormId");
var client = new ElasticClient(settings);
var myJson = #"{ ""hello"" : ""world"" }";
var response = client.Index(myJson, i => i.Index("FormId")
.Type("resp")
.Id((int)r.id)
.Refresh()
);
Nothing is inserted, and I get the following error from ES:
{Invalid NEST response built from a unsuccesful low level call on PUT: /FormId/resp/1?refresh=true}
I've tried to find some example on that but all use a predefined structure of data, instead I want to use JSON data, with unstructured data.
The above error messsage is from NEST.
Elastic replies (and write in the log) the following message:
MapperParsingException[failed to parse]; nested- NotXContentException[Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes];
Failed to parse { ""hello"" : ""world"" } ????
A few observations:
the index name needs to be lowercase
the index will be automatically created when you index a document into it, although this feature can be turned off in configuration. If you'd like to also control the mapping for the document, it's best to create the index first.
use an anonymous type to represent the json you wish to send (you can send a json string with the low level client i.e. client.LowLevel if you want to, but using an anonymous type is probably easier).
The .DebugInformation on the response should have all of the details for why the request failed
Here's an example to demonstrate how to get started
void Main()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node)
// lower case index name
.DefaultIndex("formid");
var client = new ElasticClient(settings);
// use an anonymous type
var myJson = new { hello = "world" };
// create the index if it doesn't exist
if (!client.IndexExists("formid").Exists)
{
client.CreateIndex("formid");
}
var indexResponse = client.Index(myJson, i => i
.Index("formid")
.Type("resp")
.Id(1)
.Refresh()
);
}
Now if we make a GET request to http://localhost:9200/formid/resp/1 we get back the document
{
"_index": "formid",
"_type": "resp",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"hello": "world"
}
}

Error: "Photo data or source id must be included" when I try to Upload a photo to PicasaWeb in Gdata .NET

Somebody know what I'm doing wrong?
var service = new Service("lh2", "exampleCo-exampleApp-1");
service.setUserCredentials("myuser", "mypass");
var myPhoto = new PhotoEntry
{
Title = new AtomTextConstruct(
AtomTextConstructElementType.Title,
"Puppies FTW")
};
var myMedia = new MediaFileSource(#"C:\puppies.jpg", "image/jpeg");
myPhoto.MediaSource = myMedia;
var u="https://picasaweb.google.com/data/feed/api/user/default/albumid/default";
var returnedPhoto = service.Insert(new Uri(u), myPhoto);
Actually is returning bad request error (400) with the following response string: Photo data or source id must be included
It was returning error because the Uri was wrong:
I must use:
var u="https://picasaweb.google.com/data/media/api/user/default/albumid/default";
instead:
var u="https://picasaweb.google.com/data/feed/api/user/default/albumid/default";

Categories