I'm logging user actions in ElasticSearch and I'm using C# Log4Net
I'm using the C# NEST library to access the ElasticSearch database.
My log line looks like this:
{
"_index" : "log-2016.07.27",
"_type" : "logEvent",
"_id" : "AVYrwmW5Hc5CAgECpn_X",
"_score" : 1.0,
"_source" : {
"timeStamp" : "2016-07-27T09:49:35.3774113Z",
"message" : "Upload file operation took 11683 ms",
"loggerName" : "Reviewer.Web.WebApi.GroupsController",
"identity" : "",
"level" : "INFO",
"properties" : {
"log4net:UserName" : "CORP\\g",
"log4net:ElapsedTime" : "11683",
"log4net:Identity" : "",
"IP" : "::1",
"log4net:HostName" : "GBWOTIOM68052D",
"#timestamp" : "2016-07-27T09:49:35.3774113Z"
}
}
I'd like to have the log4net:ElapsedTime value stored as an integer instead of a string.
currently I'm doing this when storing an elapsed time:
long ms = 1000;
LogicalThreadContext.Properties["log4net:ElapsedTime"] = ms;
I know I should specify a template in order to tell ElasticSearch to store the elapsed value as an integer but how to do it?
If you want elasticsearch to recognize your field you should send your data value without double-quotes.
curl -XPUT 'localhost:9200/tmp/tmp/1' -d '{
"field1":"3",
"field2":3
}'
-
curl -XGET 'localhost:9200/tmp'
{"tmp":{"aliases":{},"mappings":{"tmp":{"properties":{"field1":{"type":"string"},"field2":{"type":"long"}}}},"settings":{"index":{"creation_date":"1469621916488","uuid":"Qj64-CU5RUW6ShOyRqLZXQ","number_of_replicas":"0","number_of_shards":"1","version":{"created":"1070599"}}},"warmers":{}}}
You can see field1 is string but field2 is numeric.
Related
I'm new to C# mongo,earlier worked on Node and Mongo.
i have a collection called tasks.Below is a sample record.
{
"_id" : ObjectId("6193bfba23855443a127466a"),
"taskIdentifier" : LUUID("00000000-0000-0000-0000-000000000000"),
"title" : "PR Liquidators",
"company" : "iuytreugdfh",
"purpose" : "test purpose",
"column" : "Search",
"assignTo" : "Shiva",
"assignToId" : ObjectId("61933b47a79ac615648a7855"),
"assignToImage" : null,
"notes" : "ggh#William james ",
"done" : 0,
"taskID" : "00029",
"status" : "Pending",
"states" : [
"Alabama - AL",
"Alaska - AK"
],
"active" : true,
"updatedAtUtc" : ISODate("2021-11-18T12:26:37.616Z"),
"updatedBy" : ""
}
in my c# webapi Project i always get a array called filterCriteria from api request of below form:
filterCriteria=[
{key:"purpose",value:"test purpose",type:"eq"},
{key:"active",value:true,type:"eq"}
]
Now I want to query the mongo collection tasks using the given filterCriteria.
tried something using LINQ statements but no use --hardcoding works but dynamically not working.
How can I achieve this???
maybe you are looking for Builders:
public enum FilterType{
eq=1,//equal
gt=2//greater than
}
//************
var builder = Builders<FilterCritertiaModel>.Filter;
var query = builder.Empty;
foreach(var filterCriteriaItem in filterCriteria){
switch (filterCriteriaItem.type) {
case eq:
query &= builder.Eq(filterCriteriaItem.Key, filterCriteriaItem.Value);
case gt:
query &=builder.Gt(filterCriteriaItem.Key, filterCriteriaItem.Value);
//all cases....
}
I use firebase.database to make query from Firebase in c#, i want to make like Where in linq But i didn't find any extension method that would help.
I have CallHistory table has many properties like Rate,Id,Status and
make index in Rate property this is json of callhistory
"CallHistory" : {
"0798af9c-180c-4d67-a58d-a47043f7e36f" : {
"CreatedDate" : "0001-01-01T00:00:00Z",
"Id" : "0798af9c-180c-4d67-a58d-a47043f7e36f",
"IsActive" : false,
"IsDeleted" : false,
"Latitude" : 1.5,
"ModifiedDate" : "0001-01-01T00:00:00Z",
"Rate" : 5,
"RecipientId" : "00000000-0000-0000-0000-000000000000",
"Status" : 2,
"StatusDateTime" : "0001-01-01T00:00:00Z",
"longitude" : 1.2
},
"151c7072-0b17-44aa-a834-99c265ef897f" : {
"CreatedDate" : "0001-01-01T00:00:00Z",
"Id" : "151c7072-0b17-44aa-a834-99c265ef897f",
"IsActive" : false,
"IsDeleted" : false,
"Latitude" : 1.5,
"ModifiedDate" : "0001-01-01T00:00:00Z",
"Rate" : 4,
"RecipientId" : "00000000-0000-0000-0000-000000000000",
"Status" : 1,
"StatusDateTime" : "0001-01-01T00:00:00Z",
"longitude" : 1.2
}
}
and write this code
using Firebase.Database;
using Firebase.Database.Query;
var firebase = new FirebaseClient("https://sound-project-42ead.firebaseio.com/");
var calls = await firebase
.Child("CallHistory").OrderBy("Rate").EqualTo("4")
.OnceAsync<CallHistory>();
But it doesn;t return any data.
With search i found that there are function called OrderByChild() , But i did'nt find this method anymore
in firebase.database.query.
Is There any other dll can i install it to find orderbychild().
Firebase Realtime Database queries compare the actual type of the stored data and of the value you specify. And the string "4" is not the same as a numerical value 4.
So you'll want to pass a number:
var firebase = new FirebaseClient("https://sound-project-42ead.firebaseio.com/");
var calls = await firebase
.Child("CallHistory").OrderBy("Rate").EqualTo(4)
...
we have a problem with our indexes. We have an index on our emails but it throws errors like such:
> db.User.insert({email: "hell33o#gmail.com", "_id" : BinData(3,"iKyq6FvBCdd54TdxxX0JhA==")})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 11000,
"errmsg" : "E11000 duplicate key error index: placetobe.User.$email_text dup key: { : \"com\", : 0.6666666666666666 }"
}
})
when we have the index created with our C# driver like this
Created by C# with:
CreateIndexOptions options = new CreateIndexOptions {Unique = true};
_collection.Indexes.CreateOneAsync(Builders<User>.IndexKeys.Text(_ => _.email), options);
resulted in
{
"v" : 1,
"unique" : true,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "email_text",
"ns" : "placetobe.User",
"weights" : {
"email" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 2
}
but if we create it with the MongoDB console like this it works:
{
"v" : 1,
"unique" : true,
"key" : {
"email" : 1
},
"name" : "email_1",
"ns" : "placetobe.User"
}
I don't understand the difference between the two indexes, but they have an effect on our DB. We also have problems with a Collectin that saves names. we get duplicate exceptions on "Molly" if we try to insert "Molli". With the emails is seems to give us errors whenever we have two "gmail" emails in the collection or two ".com" emails etc.
This is a University project and we have to turn it in tomorrow. we're really in trouble, help would be much appreciated
You don't want your email to be a text Index. Text indices allow you to search large amounts of text in MongoDB like if you were parsing through comments or something. All you want is to make sure your emails aren't duplicated so you should use an ascending or descending index.
CreateIndexOptions options = new CreateIndexOptions {Unique = true};
_collection.Indexes.CreateOneAsync(Builders<User>.IndexKeys.Ascending(_ => _.email), options)
I have a collection I am trying to query using the c# driver. the document structure is:
{
"_id" : 3121 ,
"Active" : true ,
"CategoryId" : 1 ,
"Crci" : "IH" ,
"CultureId" : null ,
"DateUpdated" : {
"$date" : 1381916923120
} ,
"Description" : "National Careers Service: Actuary" ,
"Keywords" : "" ,
"MaxLevel" : null ,
"MinLevel" : null ,
"PhoneNumber" : " " ,
"Priority" : 1 ,
"Title" : "National Careers Service: Actuary" ,
"WebUrl" : "https://nationalcareersservice.direct.gov.uk/advice/planning/jobprofiles/Pages/actuary.aspx" ,
"CareerCultureExternalResources" : [
{
"CareerId" : 5 ,
"CultureId" : 1 ,
"DisplayOrder" : 1 ,
"ExternalResourceId" : 3121 ,
"Vgs" : null
}
] ,
"SubjectExternalResources" : [ ] ,
"LifestyleCategories" : null
}
the query I am trying to run is:
collection.AsQueryble().Where(
er =>
er.CareerCultureExternalResources.Any(
ccer => ccer.CareerId == request.CareerId && ccer.CultureId == request.CultureId));
passing the values careerId = 637 and cultureId = 1, I get the error: "Unsupported where clause: ((Int32)ccer.CareerId == 637)"
However on the MongoDb tutorials page it says this kind of query is covered:
http://docs.mongodb.org/ecosystem/tutorial/use-linq-queries-with-csharp-driver/
I am using version 1.8.3 of the driver
Currently, using where and a conditional clause like you've done, when using Linq, is limited to a subset of .NET data types. Instead of using a short, use a Int32/(int) instead.
I have an interesting scenario where I have a 2-level embedded array in a Mongo Document and I can't seem to figure out a way to update elements inside the 2nd level. I've tried ElemMatch but it doesn't seem to be working.
I have a Product document which has an Attributes array. This Attributes Array has multiple options. Ex. a Product could be a t-shirt, with attributes Size, Color. Each Attribute could have options. For e.g. Size has options XS, S, M, L. Now I want the ability to update the size option given the OptionId (and/or the Attribute Id).
Here's how my Mongo document looks like:
{
"Attributes" : [{
"_id" : ObjectId("52adf86912a4590a3cb322a5"),
"Name" : "Size",
"LabelText" : "Select your T-Shirt Size",
"Description" : "This is the Size of the T-Shirt",
"ShowOnDisplay" : true,
"Options" : [{
"_id" : ObjectId("52adf86912a4590a3cb322a6"),
"Name" : "XS",
"Value" : "XS"
}, {
"_id" : ObjectId("52adf86912a4590a3cb322a7"),
"Name" : "S",
"Value" : "S"
}],
"DateCreatedUtc" : new Date("12/15/2013 10:43:53"),
"DateModifiedUtc" : new Date("12/15/2013 10:43:53")
}],
"AvailableEndTimeUtc" : null,
"AvailableStartTimeUtc" : null,
"Name" : "CMR Dazzle T-Shirt ",
"Price" : {
"Value" : "25",
"Currency" : "USD"
},
"Sku" : "SKU7fb3a",
"_id" : ObjectId("52adf86912a4590a3cb322a4")
}
In the example above, I'd like to update the XS to say "X-Small". I have both the Attribute Id and the Option Id available.
I've tried using ElemMatch, I've tried simple Query.EQ("Attributes.Options._id") and then used update and nothing works. Similar to that, I'd also like to delete an option given an id.
I would greatly appreciate any help here.
I think what you want to do is the same as being discussed here. This is currently not possible in Mongo, see this JIRA.