Solr .Net Facet Term for obtaining numBuckets - c#

Trying to implement with the following Facet Term which works when querying through postman but I cannot find any equivalent in Solr.NET as there are not facet term queries. I can see by field, range, and pivots. I would need to get the numBuckets and I do not see how this can me achieved in with the Solr.NET libraries.
Postman body example.
{
"query": "*:*",
"fields": [
"user_id"
],
"filter": [
"",
],
"facet": {
"user_id": {
"mincount": 1,
"numBuckets": true,
"allBuckets": false,
"offset": 0,
"type": "terms",
"field": "user_id",
"limit": 1
}
},
"params": {
"echoParams": "none"
},
"limit": 100,
"offset": 0,
"sort": "ismail_bius asc,createdon_zius desc"
}
I have tried to pass it in the ExtraParams property of the query options but no luck on it.
Thanks.

Related

How to skip fields with default values in JSON response in HotChocolate/GraphQl

I want to remove fields from output JSON with default values (0, false) to reduce size of response, but can't find a way how to do it in HotChocolate/GraphQl.
I didn't find a settings to control it (JsonFormatter), "Optional" also not for this purposes, and there is not options to do it via query syntax.
After query to graphQl I receive a long list, with many default values in JSON output, simple example, pay attention to "sortOrder" and "isDeleted":
"values": [{
"id": 448,
"name": "Dr.",
"isDeleted": false,
"sortOrder": 0
}, {
"id": 449,
"name": "Mr.",
"isDeleted": true,
"sortOrder": 0
}, {
"id": 450,
"name": "Mrs.",
"isDeleted": false,
"sortOrder": 1
}]
Expecting result:
"values": [{
"id": 448,
"name": "Dr.",
}, {
"id": 449,
"name": "Mr.",
"isDeleted": true,
}, {
"id": 450,
"name": "Mrs.",
"sortOrder": 1
}]
Query:
getLookups(withDeleted: true) {
id
name
isDeleted
values {
id
name
isDeleted
sortOrder
}
}
Type description:
descriptor.BindFields(BindingBehavior.Explicit);
descriptor.Interface<ILookupValueType>();
descriptor.Field(f => f.Id).Type<NonNullType<IntType>>();
descriptor.Field(f => f.Name).Type<StringType>();
descriptor.Field(f => f.Image).Type<StringType>();
descriptor.Field(f => f.IsDeleted).Type<BooleanType>();
descriptor.Field(f => f.IsDefault).Type<BooleanType>();
descriptor.Field(f => f.SortOrder).Type<IntType>();
P.S. Please, don't offer pagination, it is not what I need.
And thank you for your help.

Azure Cognitive Search - match exact phrase for some fields

I have different fields in my Azure Cognitive Search but let me show you some with which I have problems.
{
"name": "Name",
"type": "Edm.String",
"searchable": true,
"filterable": false,
"retrievable": true,
"sortable": true,
"facetable": false,
"key": false,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": "standard.lucene",
"synonymMaps": []
}
and
{
"name": "Code",
"type": "Edm.String",
"searchable": true,
"filterable": false,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": false,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": "keyword",
"synonymMaps": []
}
As you can see above, for Name I set analyzer standard.lucene (I have language-specific for other fields like NameEn) and keyword analyzer for Code field.
For example, when I search by 1-1 it looks for 1 instead of 1-1. I try with double quotes but it seems I also don't work ("1-1").
The issue is that as a result I get Name with the number 1 instead of Code which have 1-1.
Do you have any idea how can I do it? I suppose I should search by the whole phrase like: "1-1" rest part of the query.
When you send query it is analyzed by analyzers of all searchable fields and then tokenized query (different for each field) will be executed against all of them.
You can send queries to analyze endpoint to debug how each analyzer is working with your query -
https://serviceName.search.windows.net/indexes/index-name/analyze?api-version=2020-06-30
In your case:
{
"text": "1-1",
"analyzer": "standard"
}
returns these tokens for Name field
"tokens": [
{
"token": "1",
"startOffset": 0,
"endOffset": 1,
"position": 0
},
{
"token": "1",
"startOffset": 2,
"endOffset": 3,
"position": 1
}
]
and for Code field
{
"text": "1-1",
"analyzer": "keyword"
}
you get
"tokens": [
{
"token": "1-1",
"startOffset": 0,
"endOffset": 3,
"position": 0
}
]
So with such query you are really looking for documents with
Name=1 | Code=1-1
If you want to search only in selected fields you can specify them using searchFields parameter.

Sub Document operations in couchbase using .net sdk

Delete a specific node from all the available documents in a bucket
Is it possible to delete an element from the children array based on the Id from the below sample document using .NET SDK for Couchbase in C#?
i.e. I need to delete all the details of Id=100( delete the entire element in the children array).
I can achieve it using N1QL. N1QL performance is slow when there are thousands of document involved in couchbase
{
"results": [{
"tutorial": {
"type": "contact",
"title": "Mr.",
"fname": "Ian",
"lname": "Taylor",
"age": 56,
"email": "ian#gmail.com",
"children": [{
"Id": "100",
"Details": [{
"fname": "Abama",
"age": 17,
"gender": "F"
}]
},
{
"Id": "101",
"Details": [{
"fname": "Alex",
"age": 17,
"gender": "M"
}]
}
],
"hobbies": [
"golf",
"surfing"
],
"relation": "cousin"
}
}]
}

Azure Cosmos DB Add Composite Index for Array of String

I am trying to add a new composite index to do multiple fields search.
I would like to know thing to consider while adding a new Composite index and will it work for array string?
Sample Cosmos Document
{
"id": "ed78b9b5-764b-4ebc-a4f2-6b764679",
"OrderReference": "X000011380",
"SetReferences": [
"000066474884"
],
"TransactionReference": "ed78b9b5-764b-4ebc-6b7644f06679",
"TransactionType": "Debit",
"Amount": 73.65,
"Currency": "USD",
"BrandCode": "TestBrand",
"PartitionKey": "Test-21052020-255",
"SettlementDateTime": "2020-05-21T04:35:35.133Z",
"ReasonCode": "TestReason",
"IsProcessed": true,
}
My Existing index policy
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/PartitionKey/?"
},
{
"path": "/BrandCode/?"
}
],
"excludedPaths": [
{
"path": "/*"
},
{
"path": "/\"_etag\"/?"
}
],
"compositeIndexes": [
[
{
"path": "/PartitionKey",
"order": "ascending"
},
{
"path": "/IsProcessed",
"order": "ascending"
}
]
]
}
To fetch data from Array of string SettlementReferences, IsProcessed, ReasonCode.
SELECT * FROM c WHERE ARRAY_CONTAINS(c.SettlementReferences, '00884') and c.IsProcessed = true and c.ReasonCode = 'TestReason'
I am planning to add the following policy
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/PartitionKey/?"
},
{
"path": "/BrandCode/?"
}
],
"excludedPaths": [
{
"path": "/*"
},
{
"path": "/\"_etag\"/?"
}
],
"compositeIndexes": [
[
{
"path": "/PartitionKey",
"order": "ascending"
},
{
"path": "/IsProcessed",
"order": "ascending"
}
],
[
{
"path": "/SettlementReferences",
"order": "ascending"
},
{
"path": "/IsProcessed",
"order": "ascending"
},
{
"path": "/ReasonCode",
"order": "ascending"
}
]
]
}
Please let me know if this change is sufficient?
Moreover, I tried to compare RU's before and after the change. I don't see any massive difference, both coming around 133.56 Rus.
Is there anything more I need to consider for optimized performance?
Composite Indexes will not help with this query and overall don't have any impact on equality statements. They are useful when doing order by's in your queries. This is why you don't see any RU/s reduction in your query. However, you will notice increased RU/s on writes.
If you want to improve your query performance you should add any properties in your where clauses into the "includedPaths" in your index policy.
Another thing to point out too is generally it is a best practice to by default index everything and selectively add properties to excludedPaths. This way, if your schema changes it will be indexed automatically without having to rebuilt your index.
As mark mentioned we need to add include path for Array "/SettlementReferences /[]/?". After adding my number of Ru's reduced from 115 to 5 ru's.

Wildcard value in JSONPath

I have the below JSON that I am trying to interpret, using json.net.
{
"platformUpdateDomain": 0,
"platformFaultDomain": 0,
"vmAgent": {
"vmAgentVersion": "2.5.1198.709",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"level": "Info",
"displayStatus": "Ready",
"message": "GuestAgent is running and accepting new configurations.",
"time": "2015-04-21T11:42:44-07:00"
}
]
},
"disks": [
{
"name": "myosdisk",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"time": "2015-04-10T12:44:10.4562812-07:00"
}
]
}
],
"statuses": [
{
"code": "ProvisioningState/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"time": "2015-04-10T12:50:09.0031588-07:00"
},
{
"code": "PowerState/running",
"level": "Info",
"displayStatus": "VM running"
}
]
}
I wish to extract the Status, where the code contains the below value:
PowerState
However, I cannot work out how to do this, I can match against the entire string using Json.Net, but I'd like to
myJsonJObject.SelectToken("$.statuses[?(#.code == 'PowerState/running')]");
However, part of the "code" value can change, so I'd like to try and search based on the below condition
myJsonJObject.SelectToken("$.statuses[?(#.code == 'PowerState/*')]");
What is the correct Jsonpath expression to do this? Matching against a substring would also work, but again, I cannot find an example to do this.
Workaround is to use linq.
select all the status objects, filter on the code value, which has been converted to a string to use the contains method.
var x = myJsonJObject.SelectToken("$.statuses").Where(y => ((string)y.SelectToken("$.code")).Contains("PowerState"));

Categories

Resources