I want to translate something like
MATCH (s)
WHERE ID(s) = 65110
RETURN s
into C# to use it with the Graph client. My main problem is that I want to get a node by using the internal id of Neo4j, which is absolutely no problem in Cypher but how can I do this in Graph client?
var query = client.Cypher
.Match("(s)")
.Where((Event s) => ID(s) == 65110)
.Return(...);
This was my first approach but of course that does not work. Can you tell me how to use this ID function of Cypher to get a node with a specific internal Neo4j id by using the Graph client for C#?
For explanation, client is a variable, that connects to the Graph Client of Neo4j:
var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "username", "Password");
client.Connect();
I'm using a parameter here, as that's the best way to ensure the query will be compiled and cached, obviously you could just put in the ID. Generally - you want to avoid using the ID of a Neo4j item, in fact - I would strongly urge you to add you're own ID field. But! here it is anyhews :)
var query = client.Cypher
.Match("(s)")
.Where("ID(s) = {idParam}")
.WithParam("idParam", 65110)
.Return(s => s.As<Node<string>>());
Related
Using C#, I am trying execute a query on Google Spanner db. I understand I can use the SpannerClient and all the current documentation explains how to execute a query quite simply, however these examples all assume default environment credentials.
I would like to execute a query against a given database but using custom credentials. So something like
var credentials = GoogleCredential.FromJson(jsonData);
SpannerClient client = new SpannerClient(connectionString, credentials)
var cmd = client.CreateSelectCommand("SELECT SingerId, AlbumId, AlbumTitle FROM Albums");
etc
I am currently unable to figure out how to do this?
Thanks
Currently this isn't as clean as we'd like it to be. You need to create a ChannelCredentials for the credentials, and provide that to the SpannerConnectionStringBuilder:
// First load the credentials, scope them, and convert to ChannelCredentials.
// You may want to move this to a separate method.
var googleCredential = GoogleCredential.FromJson(jsonData);
googleCredential = googleCredential.CreateScoped(SpannerClient.DefaultScopes);
// Use self-signed JWTs for service accounts.
// (This isn't strictly required, but reduces network usage.)
if (googleCredential.UnderlyingCredential is ServiceAccountCredential serviceCredential)
{
googleCredential = GoogleCredential.FromServiceAccountCredential(
serviceCredential.WithUseJwtAccessWithScopes(true));
}
// Note: this requires a using directive of "using Grpc.Auth;"
var channelCredentials = googleCredential.ToChannelCredentials();
// Now create a SpannerConnection with the SpannerCredentials
using var conn = new SpannerConnection(connectionString, credentials);
using var cmd = conn.CreateSelectCommand("SELECT ...");
...
We definitely hope to improve this - we have a tracking bug you might want to subscribe to so that you can simplify your code when it's fixed.
I am trying to use the Nest client to consume an Elasticsearch instance.
However, the /_search endpoint is in fact /search.
Is there any possible way to change the behavior of the client to reflect this change?
I have tried looking into the source code but just can't figure out a way this can be done.
Disclaimer: I have no control over the ES instance, neither I know if there is some sort of proxy in the middle that alters the /_search into /search.
Thanks in advance.
/search is not an API endpoint in Elasticsearch. It is not possible to change the API endpoints within the client, without changing the API specs from which it is generated and recompiling.
You can use the low level client's DoRequest and DoRequestAsync methods to call
a non-standard API
var client = new ElasticClient();
var request = new SearchRequest<LogMessage>
{
Query = new MatchQuery
{
Field = Infer.Field<LogMessage>(f => f.Level),
Query = "warning"
}
};
var response = client.LowLevel.DoRequest<SearchResponse<LogMessage>>(
Elasticsearch.Net.HttpMethod.POST,
"/search",
PostData.Serializable<ISearchRequest>(request)
);
Am new to Elastic search and NEST, I am trying to get connected with my ES server through NEST. My ES Connection initialization looks like below.
ElasticClient client = null;
public void Connect()
{
var local = new Uri("http://192.168.40.95:9200/");
var settings = new ConnectionSettings(local).DisableDirectStreaming();
client = new ElasticClient(settings);
settings.DefaultIndex("gisgcc18q4");
ReadAllData();
}
public void ReadAllData()
{
var x= client.Search<dynamic>(s=> s.MatchAll());
}
The response is attached as image below,
I am Never getting any Hits, or data. Did i made any mistake in my connector, Also please suggest me good tutorials to convert JSOn ES query to NEST as well.
Looking at the Uri in the screenshot
POST /gisgcc18q4/object/_search?typed_keys=true
suggests that you're using a version older than 7, such as 5 or 6, where document types are used. In this case, the document type name "object" has been inferred from the dynamic type passed as the generic parameter argument, but I suspect that documents have not been indexed with a document type name of "object", but something else.
If the index "gisgcc18q4" only contains one type of document, you can use
var x = client.Search<dynamic>(s=> s.MatchAll().AllTypes());
Or you can pass the specific document type name to use
var x = client.Search<dynamic>(s=> s.MatchAll().Type("_doc"));
A good getting started tutorial for the client is the elasticsearch-net-example GitHub repository. It is a walkthrough in building out a ASP.NET Core web application to search Nuget packages.
Your connection looks fine, can you please validate the detailed summary under DebugInfrormation by clicking on it and get the row query and response.
After apply same query on Postman.
Please copy and paste below expression on quick watch window on the same line which is displayed in your screenshot.
((Elasticsearch.Net.ApiCallDetails)response.ApiCall).DebugInformation
You will get the detailed information, it will be helpful for you to investigate this issue.
I am writing an API to allow a client to consume time-ordered data. There is a lot of it (10k+ records per client) so I don't want to dump all of it this back to the client and order there, hence my need to both order it and page it server-side. I have the paging working, but I cannot see how to add ordering.
I've seen recommendations to sort on the client, but given the potential amount of data that is not going to work in this case. Is there a workaround?
Here is what I have so far:
var options = new FeedOptions {
MaxItemCount = 25,
RequestContinuation = continuationToken
}
var query = String.Format("SELECT * FROM TimelineEvent t WHERE t.acc_id = '{0}' AND t.removed != true", accountId);
// ORDER BY in the query text doesn't appear to work
var events = client.CreateDocumentQuery<TimelineEvent>(colSelfLink, query, options).AsDocumentQuery();
var response = await query.ExecuteNextAsync<TimelineEvent>();
It's not supported out of the box, but you can implement a stored procedure that does this.
The msft product group has supplied some code samples here: https://code.msdn.microsoft.com/windowsazure/Azure-DocumentDB-NET-Code-6b3da8af/sourcecode?fileId=132409&pathId=34503205
Look under server side script, JS folder, you'll see an "orderby" script that does this. Adjust to your needs and try it.
ORDER BY is now officially supported by DocumentDB
https://azure.microsoft.com/en-us/documentation/articles/documentdb-orderby/
I am creating a client application that connects to a website in order to execute queries. I am not enabling the client to connect directly to the database but he can perform queries through the website.
The way I execute queries through the website is through linq. For example I may do:
MyEntities db = new MyEntities();
var customers = db.Customers.ToList();
Since the client does not have the connection string and sql server does not allow remote connections when he executes the above code it will obviously not work. My question is how can the client send that query to the web service?
The reason why I need this is because there are so many different types of queries and for each different one I have to create a different page. For example I have GetInvoices.aspx, GetCustomers.aspx, and I am always creating new ones just because I dont want the client to connect directly to the database. It will be nice if I could serialize the linq query and send that to the server. the server then should validate that I am not doing a delete statement for example and if thats the case then execute the query.
Eidt
This is what I am going to do for only select statements:
// Note connection string only have basics. It does not have password nor database.
public static string GenerateSelectQuery<T>(Func<Common.Data.TcEntities, IQueryable> method)
{
Common.Data.TcEntities db = new Common.Data.TcEntities(#"metadata=res://*/Data.Model1.csdl|res://*/Data.Model1.ssdl|res://*/Data.Model1.msl;provider=System.Data.SqlClient;provider connection string=""""");
var query = method(db);
return query.ToString();
}
then if I wish to create a custom query I will do:
var query = GenerateSelectQuery<Customer>(db => db.Customers.Where(x=>x.FirstName.Contains("a")));
I will send then that string to the server and expect an array of Customers. On the server side I will make sure string starts with select and it does not contain --.
Implementing a WCF Data Services, http client can query your data using the OData protocol.
For example, applying a select Name on your customers collections will be queryable using the http url:
http://youdomain/yourWCFDataServices.svc/Customers()?$select=Name