Hey I trying to update existing document of ElasticSearch, I found a cURL code from Elasticsearch site
Note: Sam type with 2 document is already exists I just want to update a existing field
POST /EmployeeIndex/Sam/2/_update
{
"doc" : {
"Nested" : true,
"views": 0
}
}
Its working perfectly how I need but please help me to convert it to NEST, as i working on .NET, I managed to write a code
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new { Nested= true })
.RetryOnConflict(3)
.Refresh());
But it always creating a new field in my document instead of updating existing one.
Please see attached screenshot with a code
Please help guys.
What you need is a PartialUpdate. Applied on your example, the following code should do what you expect.
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new {IsActive ="true", Views="0"})
.DocAsUpsert()
);
Is it possible that you are already there but be just facing a casing missmatch issue? see from Nest reference:
Property Name Inference In many places NEST allows you to pass
property names and JSON paths as C# expressions, i.e:
.Query(q=>q
.Term(p=>p.Followers.First().FirstName, "martijn")) NEST by default will camelCase properties. So the FirstName property above
will be translated to "followers.firstName".
This can be configured by setting
settings.SetDefaultPropertyNameInferrer(p=>p); This will leave
property names untouched.
Properties marked with [ElasticAttibute(Name="")] or
[JsonProperty(Name="")] will pass the configured name verbatim.
...
Note that you are creating a dynamic object for the update so, i belive attributes might not a be a solution if you keep it that way
Related
I have an array field in my collection which have value with properties or empty value as "[]"
For fetching the documents having empty "[]" value in mongodb i use
db.getCollection('collection').find({"ArrayFieldName":{$eq:[]}})
This gives me result as expected. But when i try to form this query in the C# using mongodb driver i couldnt get the expected Result.
I tried,
filterBuilder.Eq("ArraryFieldName", "[]") and filterBuilder.Eq("ArraryFieldName", new ArraryClassName(){})
Need help with C# filter builder to specify $eq:[] for arrary field.
An instance of ArraryClassName clearly won't work because it's not an array instance - it's a single object. Likewise "[]" won't work because it's a string.
You can check directly translate your CLI query to this filter:
Builders<BsonDocument>.Filter.Eq<BsonArray>("ArraryFieldName", new BsonArray())
Though if you simply want to check that the existing array is empty, you can use this filter instead:
Builders<BsonDocument>.Filter.Size("ArraryFieldName", 0)
P.S. I would strongly suggest using C# data models as it makes everything much easier to work with.
Also, you have called your field ArraryFieldName (notice the extra r at the end of Array). If you don't have existing data with this misspelled property name, you might want to correct the spelling.
I have asked to create a function that can update a MongoDb collection by passing it's column names and corresponding values.The function that I wrote(in test phase now) will accept column names, values, collection name etc.before updating I want to check whether the given collection exists and column names provided exists in a that collection and if everything is fine go and update the collection.I was able to check if a collection exists or not but failed in doing the same for Columns.
I found this in Mongodb website
{ item : { $exists: false } }
but i didn't found the exact c# code for doing the same. Is it possible with c# to check if a column exists in MongoDb ? MongoDb version 4.0 is what i am using now.
Note : I don't have any strongly typed data, Since the function is unaware of the collection and the type of data it holds. The goal is to accept column names and values and update to those fields that have passed to it.
If you want to find documents where a property doesn't exist, you can use the following code:
var modelsWithoutItem = collection.Find(
Builders<DocModel>.Filter.Exists(m => m.Item, false)
);
or if you don't have strongly typed data:
var modelsWithoutItem = collection.Find(
Builders<BsonDocument>.Filter.Exists("item", false)
);
var fieldExists = _collection.Find(Builders<BsonDocument>.Filter.Exists("item",true));
if (fieldExists.CountDocuments() > 0){
// yes document with this field is available
}else{
// No documents with that field name exists
}
#john Thank you for the quick response, with a bit of update i have got what I wanted.
I have been trying to populate my variable bar with json fields from curl's POSTFIELDS attribute when invoking my workflow from an API using PHP. Below is a simple json passed when invoking the endpoint not as part of the URL but hidden POSTed data:
{"salesValue":5000,"authorId":2}
The properties above should be injected in Formatter Node where I generate the SQL statetement used by the ODBC driver to query our back-end database. I have been told that I can only do this, for now, by using the SCRIPT Node as I do not recall C# as having support for manipulating JSON Object out of the box. If I am behind with regards to that someone please lead me to an answer.
Question is: does Flowger support JSON Serialization, Deserialization, Decoding and/or encoding? There is a framework called JSON.Net for example. Can I use this if I want to manipulate my fgRequestBody property frfom my variable bar?
Try the below steps to get the desired results:
1 - Add a variable bar with two special properties: FgRequestBody and FgRequestContentType. Make sure that you specify the content type in the workflow, which will be application/json in your instance.
2 - Add a 'JSON Convert' directly after the start node and point your variable bar FgRequestBody to the input of Json on the Json Convert. This will convert json to xml.
3 - Add a 'XFormat' node and plug the xml output from the Json Convert to the 'XML Document' property. Right click on the node and add a new custom property with the name of the field that you would like to extract. In the custom property value, add the xpath to the value. In the Expression property of the node, add your sql statement e.g.
select * from tableName where name = '{customProperty}'
The results from this will be your sql query.
Troubleshooting Tip:
Use Postman Add-In (Chrome) or RESTClient (Firefox) to verify the results. You should see the node generation in the activity log within Flowgear. If you do not see this, then add a AllowedOrigin of * in your Flowgear Site properties. See the following for reference to this:http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
using Salesforce's enterprise wsdl I am trying to save opportunity line items along with opportunity. But I am getting following error:
INVALID_FIELD: No such column 'OpportunityLineItems' on entity 'Opportunity' If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Here is my code to create line items:
if (oppLineItems.Count > 0)
{
sfOpportunity.OpportunityLineItems = new QueryResult();
sfOpportunity.HasOpportunityLineItem = true;
sfOpportunity.OpportunityLineItems.records = oppLineItems.Values.ToArray();
Pricebook2 priceBook = new Pricebook2();
priceBook.PricebookEntries = new QueryResult();
priceBook.PricebookEntries.records = new List<PricebookEntry>() { priceBookEntry }.ToArray();
sfOpportunity.Pricebook2 = priceBook;
}
oppLineItems is a dictionary whole values have proxy objects of opportunity line items.
sfOpportunity is proxy object of Opportunity which is then sent to Salesforce.
There's a very similar question here, not sure if we should mark it as duplicate though: Salesforce: Creating OpportunityLineItems as part of the Opportunity in PHP
OpportunityLineItems on Opportunity isn't a real field. Its something called "relationship name"... Similar to table alias in normal databases, useful especially when you're making joins. And HasOpportunityLineItem is a readonly field :) And I don't think these should be QueryResult, check http://www.salesforce.com/us/developer/docs/api/Content/sample_create_call.htm for some hints?
You will need to insert the Opportunity first, the operation result will give you the record's Id. Then you should insert a list (array) of the line items.
This means 2 API calls and extra considerations what to do when the Opp header saves OK but one or more lines fails... So maybe it's good idea to write an Apex webservice like I suggested in that other question.
I am using XMLSerialization to pass data from a client based Win7 application to our server (Server 2008 R2) via a Pipe communication process. I have been brought into this project to finish the previous developer's efforts who abandoned it ... therefore I am presently trying to fix the C# code in VS2010 that doesn't work.
The problem is that I cannot obtain full serialization of the resulting output from the following method which is in "public partial class Test". We have a table defined in the MS Compact Server database (named "Test") which matches each item below and has a FK to the "Channel" table, based on matching TestID's in both tables. EntityCollection is based on its relationship to the "Channel" table:
public Test(Guid TestID, String TestName, String TestRemarks, String ScriptPath,
EntityCollection<Channel> TChannels)
{
ID = TestID;
Name = TestName;
Remarks = TestRemarks;
Path = ScriptPath;
Channels = TChannels;
}
Here is a sample of how it is used in the execution of the method:
Test T = new Test(NewID, "Test1", "Test_120912-1729",
"C:\\Temp\\TestScript_16.txt", TChannels);
Here is the result of the serialization process:
<DataCore xsi:type="Test">
<ID>bc6a8ef7-c31f-404d-8108-86219d45be63</ID>
<Name>Test1</Name>
<Remarks>Test_120912-1729</Remarks>
<Path>C:\Temp\TestScript_16.txt</Path>
</DataCore>
The first four parameters serialize fine, but the last one (the EntityCollection) is failing to do so. However, if I try to serialize "TChannels" by itself (outside the "Test" function) the serialization of each Test Channel works perfectly. I don't fully understand the limitations/requirements for utilizing XMLserialization to solve this problem. Why am I unable to serialize the EntityCollection< > from within the function?
Thanks for your assistance!
I finally found a solution to the above problem. While the many suggestions were appreciated, none of them provided a solution to my inability to XmlSerialize a child EntityCollection. I dug deeper and looked into the ADO.NET Framework and found within the auto generated code in my database Model.Designer.cs file, an [XmlIgnoreAttribute()] near the beginning of Navigation Properties in my Test (EdmEntityTypeAttribute).
I simply removed the [XmlIgnoreAttribute()] line completely and now all the child objects of "Channels" from the EntityCollection<> are Serialized properly. I hope this can help others who are also unable to Serialize child objects.
Thanks #Dave R.