Spell corrections not working when refining queries with aggregations - microsoft-graph-api

I'm searching for list items using the /search/query endpoint of MS Graph. I want to use aggregations and spell checking. This is my request
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "inspring"
},
"fields": [
"title"
],
"aggregations": [
{
"field": "fileType",
"size": 20,
"bucketDefinition": {
"sortBy": "count",
"isDescending": "true",
"minimumCount": 0
}
}
],
"queryAlterationOptions": {
"enableModification": true
}
}
]
}
It returns no results, since the search term was not spell checked and modified:
{
"value": [
{
"searchTerms": [
"inspring"
],
"hitsContainers": [
{
"total": 0,
"moreResultsAvailable": false
}
]
}
],
"#odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.searchResponse)"
}
However, when I remove the aggregations and use the following request, it works:
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "inspring"
},
"fields": [
"title"
],
"queryAlterationOptions": {
"enableModification": true
}
}
]
}
Response:
{
{
"value": [
{
"searchTerms": [
"inspiring"
],
"hitsContainers": [
{
"hits": [...],
"total": 64,
"moreResultsAvailable": true
}
],
"queryAlterationResponse": {
"originalQueryString": "inspring",
"queryAlteration": {
"alteredQueryString": "inspiring",
"alteredHighlightedQueryString": "inspiring",
"alteredQueryTokens": [
{
"offset": 0,
"length": 8,
"suggestion": "inspiring"
}
]
},
"queryAlterationType": "modification"
}
}
],
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}
How do I have to change my request to make query alterations work with aggregations?

Related

Issue with fetching a custom tileset from CARTO and displaying it on a MapBox map iOS Swift

I'm attempting to fetch a custom tileset from CARTO using the documentation I found that the way to fetch from the API doc is:
curl --location --request GET 'https://gcp-us-east1.api.carto.com/v3/maps/carto_dw/tileset?name=carto-demo-data.demo_tilesets.nasadem_glo_quadgrid15' --header 'Authorization: Bearer <your access token>'
I made that request on Swift as follows:
{
let urlString = "\(environment.apiBaseURL)/v3/maps/\(environment.connection)/tileset"
return Future<CartoTileJsonResponse, Error> { [weak self] promise in
self?.session
.request(urlString,
method: .get,
parameters: ["name": tileSetName]
)
.validate()
.responseData(completionHandler: { response in
if let error = response.error {
promise(.failure(error))
return
}
guard let data = response.value else {
promise(.failure(response.error ?? NSError(domain: "unknow error", code: 999, userInfo: nil)))
return
}
do {
let cartoTileJsonResponse = try JSONDecoder().decode(CartoTileJsonResponse.self, from: data)
promise(.success(cartoTileJsonResponse))
} catch(let error) {
debugPrint(error)
promise(.failure(error))
}
})
}
}
As the name of the function says this return a new URL which I also make a GET request which finally returns a tilejson as shown:
{
"name": "NiallsFarm_Tileset_1_NDVI",
"tilejson": "3.1.0",
"center": [
-2.637422918924969,
55.96538584577466,
15
],
"description": "",
"maxzoom": 15,
"tilestats": {
"layers": [
{
"layer": "default",
"attributeCount": 2,
"count": 22146,
"geometry": "Polygon",
"attributes": [
{
"type": "String",
"attribute": "fieldName",
"categories": [
{
"category": "South Tempriggs",
"frequency": 7587
},
{
"category": "Kirklands",
"frequency": 6603
},
{
"category": "East Lothian",
"frequency": 4677
},
{
"category": "Crumstanes",
"frequency": 3279
}
]
},
{
"quantiles": {
"3": [
0.5691,
0.658
],
"4": [
0.5328,
0.6307,
0.6627
],
"5": [
0.5112,
0.5942,
0.6515,
0.6658
],
"6": [
0.5004,
0.5699,
0.6307,
0.6578,
0.6675
],
"7": [
0.4899,
0.5509,
0.6055,
0.6464,
0.6604,
0.6689
],
"8": [
0.4824,
0.5344,
0.5841,
0.6303,
0.6545,
0.6627,
0.6697
],
"9": [
0.4768,
0.5212,
0.5705,
0.6123,
0.6436,
0.6576,
0.6646,
0.6705
],
"10": [
0.4708,
0.5112,
0.5574,
0.5937,
0.6303,
0.6516,
0.6596,
0.6657,
0.6712
],
"11": [
0.4674,
0.504,
0.5447,
0.5801,
0.6151,
0.6413,
0.6555,
0.6613,
0.6666,
0.6718
],
"13": [
0.4594,
0.4931,
0.5235,
0.5607,
0.5872,
0.617,
0.6401,
0.6534,
0.6591,
0.6641,
0.6682,
0.6726
],
"14": [
0.4542,
0.4899,
0.5164,
0.5502,
0.5779,
0.6048,
0.6303,
0.6468,
0.6559,
0.6606,
0.665,
0.6688,
0.6731
],
"15": [
0.4514,
0.4866,
0.5112,
0.541,
0.5705,
0.5937,
0.6192,
0.6387,
0.6516,
0.6576,
0.6617,
0.6657,
0.6693,
0.6732
],
"16": [
0.4496,
0.4824,
0.5052,
0.5344,
0.5626,
0.5841,
0.6089,
0.6303,
0.6448,
0.6545,
0.6588,
0.6627,
0.6663,
0.6697,
0.6736
],
"17": [
0.4451,
0.4792,
0.5026,
0.5263,
0.5538,
0.5767,
0.5977,
0.6207,
0.6381,
0.6504,
0.6562,
0.66,
0.6637,
0.6669,
0.6702,
0.6738
],
"18": [
0.4417,
0.476,
0.499,
0.521,
0.547,
0.571,
0.5885,
0.612,
0.6304,
0.6434,
0.6531,
0.6578,
0.6609,
0.6646,
0.6675,
0.6706,
0.674
],
"19": [
0.4394,
0.4729,
0.4952,
0.5154,
0.5407,
0.5643,
0.5821,
0.6018,
0.6226,
0.6372,
0.6483,
0.6551,
0.6587,
0.662,
0.6653,
0.668,
0.6709,
0.6742
],
"20": [
0.4366,
0.4708,
0.4921,
0.5112,
0.5341,
0.5575,
0.576,
0.5941,
0.6135,
0.6304,
0.6423,
0.6521,
0.6564,
0.6596,
0.6627,
0.6658,
0.6684,
0.6712,
0.6744
],
"12We ": [
0.4622,
0.4983,
0.5344,
0.5705,
0.6005,
0.6303,
0.649,
0.6576,
0.6627,
0.6675,
0.6722
]
},
"attribute": "NDVI",
"min": 0.2076,
"avg": 0.5944896234082888,
"type": "Number",
"max": 0.6885,
"sum": "13165.56719999999999590190036258263717172608"
}
]
}
],
"layerCount": 1
},
"tiles": [
"https://gcp-us-east1.api.carto.com/v3/maps/omegacrop-production/tileset/{z}/{x}/{y}?name={NAME}&partition=12_15_16142_16145_10208_10211_3999_1&formatTiles=mvt&cache=1653383237150&access_token={ACCES_TOKEN}"
],
"minzoom": 12,
"attribution": "",
"bounds": [
-2.6481308960412906,
55.9604080548856,
-2.62664091461468,
55.97227003506276
],
"vector_layers": [
{
"field": {
"fieldName": "String",
"NDVI": "Number"
},
"id": "default",
"minzoom": 12,
"geometry_type": "Polygon",
"maxzoom": 15
}
]
}
Which I'm not being able to display on Mapbox Map using either Raster or Vector Layers. Also when trying to do a GET request from the tiles url the tilejson return I'm receiving the following error:
{
"error": "invalid zoom value, must be an integer number greater than or equal to 0",
"status": 400,
"message": "invalid zoom value, must be an integer number greater than or equal to 0",
"z": null,
"x": null,
"y": null
}
If anyone have experienced this or may know what I may be doing wrong it would be highly appreciated.

Rails Searchkick not returning results when I use a where statement

I run
Post.search("daniel")
I get 60+ results
Post.where(archive: true)
I get 60+ results
Post.search("daniel", where: { archive: true }
Here is the full searchkick query.
I get 0 results
{
"query": {
"bool": {
"must": {
"bool": {
"should": [
{
"dis_max": {
"queries": [
{
"multi_match": {
"query": "daniel",
"boost": 10,
"operator": "and",
"analyzer": "searchkick_search",
"fields": [
"*.analyzed"
],
"type": "best_fields"
}
},
{
"multi_match": {
"query": "daniel",
"boost": 10,
"operator": "and",
"analyzer": "searchkick_search2",
"fields": [
"*.analyzed"
],
"type": "best_fields"
}
},
{
"multi_match": {
"query": "daniel",
"boost": 1,
"operator": "and",
"analyzer": "searchkick_search",
"fuzziness": 1,
"prefix_length": 0,
"max_expansions": 3,
"fuzzy_transpositions": true,
"fields": [
"*.analyzed"
],
"type": "best_fields"
}
},
{
"multi_match": {
"query": "daniel",
"boost": 1,
"operator": "and",
"analyzer": "searchkick_search2",
"fuzziness": 1,
"prefix_length": 0,
"max_expansions": 3,
"fuzzy_transpositions": true,
"fields": [
"*.analyzed"
],
"type": "best_fields"
}
}
]
}
}
]
}
},
"filter": [
{
"term": {
"archive": {
"value": true
}
...
I looked at the searchkick gem doc and I am following exactly what they have listed to do. The normal search works fine and it only returns 0 posts when I add the where clause.
Without the where clause it shows all the posts which have "daniel" in the and it breaks when the where clause is added.
What am I doing wrong here? Is more information needed?
require 'elasticsearch/model'
class Post < ApplicationRecord
searchkick text_start: [:title]

Elastic search - aggregation filter for product options

I have a products catalogue where every product is indexed as follows (queried from http://localhost:9200/products/_doc/1) as sample:
{
"_index": "products_20201202145032789",
"_type": "_doc",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"title": "Roncato Eglo",
"description": "Amazing LED light made of wood and description continues.",
"price": 3990,
"manufacturer": "Eglo",
"category": [
"Lights",
"Indoor lights"
],
"options": [
{
"title": "Mount type",
"value": "E27"
},
{
"title": "Number of bulps",
"value": "4"
},
{
"title": "Batteries included",
"value": "true"
},
{
"title": "Ligt temperature",
"value": "warm"
},
{
"title": "Material",
"value": "wood"
},
{
"title": "Voltage",
"value": "230"
}
]
}
}
Every option contains different value, so there are many Mount type values, Light temperature values, Material values, and so on.
How can I create an aggregation (filter) where I can let customers choose between various Mount Type options:
[ ] E27
[X] E14
[X] GU10
...
Or let them choose from different Material options displayed as checkboxes:
[X] Wood
[ ] Metal
[ ] Glass
...
I can handle it on frontend once the buckets are created. Creation of different buckets for these options is What I am struggling with.
I have succesfully created and displayed and using aggregations for Category, Manufacturer and other basic ones. Thes product options are stored in has_many_through relationships in database. I am using Rails + searchkick gem, but those allow me to create raw queries to elastic search.
The prerequisite for such aggregation is to have options field as nested.
Sample index mapping:
PUT test
{
"mappings": {
"properties": {
"title": {
"type": "keyword"
},
"options": {
"type": "nested",
"properties": {
"title": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
}
}
}
}
Sample docs:
PUT test/_doc/1
{
"title": "Roncato Eglo",
"options": [
{
"title": "Mount type",
"value": "E27"
},
{
"title": "Material",
"value": "wood"
}
]
}
PUT test/_doc/2
{
"title": "Eglo",
"options": [
{
"title": "Mount type",
"value": "E27"
},
{
"title": "Material",
"value": "metal"
}
]
}
Assumption: For a given document a title under option appears only once. For e.g. there can exists only one nested document under option having title as Material.
Query for aggregation:
GET test/_search
{
"size": 0,
"aggs": {
"OPTION": {
"nested": {
"path": "options"
},
"aggs": {
"TITLE": {
"terms": {
"field": "options.title",
"size": 10
},
"aggs": {
"VALUES": {
"terms": {
"field": "options.value",
"size": 10
}
}
}
}
}
}
}
}
Response:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"OPTION" : {
"doc_count" : 4,
"TITLE" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Material",
"doc_count" : 2,
"VALUES" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "metal",
"doc_count" : 1
},
{
"key" : "wood",
"doc_count" : 1
}
]
}
},
{
"key" : "Mount type",
"doc_count" : 2,
"VALUES" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "E27",
"doc_count" : 2
}
]
}
}
]
}
}
}
}

Geojson gets distorted when trying to render in vega

I try to render a geojson in vega.
I found this example which work fine:
How to read geojson with vega
however, when trying to replace the geojson with one of mine, the features get completely distorted.
{"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"width": 500,
"height": 600,
"autosize": "none",
"signals": [
{
"name": "translate0",
"update": "width / 2"
},
{
"name": "translate1",
"update": "height / 2"
}
],
"projections": [
{
"name": "projection",
"type": "mercator",
"scale": 1000,
"rotate": [
0,
0,
0
],
"center": [
17,
-3
],
"translate": [
{
"signal": "translate0"
},
{
"signal": "translate1"
}
]
}
],
"data": [
{
"name": "drc",
"url": "https://gist.githubusercontent.com/thomas-maschler/ef9891ef03ed4cf3fb23a4378dab485e/raw/47f3632d2135b9a783eeb76d0091762b70677c0d/drc.geojson",
"format": {
"type": "json",
"property": "features"
}
}
],
"marks": [
{
"type": "shape",
"from": {
"data": "drc"
},
"encode": {
"update": {
"strokeWidth": {
"value": 0.5
},
"stroke": {
"value": "darkblue"
},
"fill": {
"value": "lightblue"
},
"fillOpacity": {
"value": 0.5
}
},
"hover": {
"fill": {
"value": "#66C2A5"
},
"strokeWidth": {
"value": 2
},
"stroke": {
"value": "#FC8D62"
}
}
},
"transform": [
{
"type": "geoshape",
"projection": "projection"
}
]
}
]
}
Here is what they are suppose to look like
https://gist.github.com/thomas-maschler/ef9891ef03ed4cf3fb23a4378dab485e
What am I getting wrong?
Thanks,
Thomas
Not sure what happened. It seems your geojson was corrupt, but not really as I eventually could parse it in www.mapshaper.org. I reduced the file to 35% and then it parsed normally:
Vega-lite spec below (compile to Vega code in the editor if needed):
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"width": 700,
"height": 500,
"config": {"view": {"stroke": "transparent"}},
"layer": [
{
"data": {
"url": "https://gist.githubusercontent.com/mattijn/2ce897c2020a6e5b7ae6baf03dffe179/raw/564b6d484657864dcb77d0bb18db00fc7dc7668d/drc.geojson",
"format": {"type": "json", "property": "features"}
},
"mark": {"type": "geoshape", "stroke": "white", "strokeWidth": 1},
"encoding": {"color": {"value": "#bcbcbc"}}
}
]
}

elastic search parsing_exception for boost query

I'm trying to boost up the query using elastic search. Headlines that are published recently must be boosted up and should come on top. However, I have return the following code:
{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"match": {
"keywords": {
"query":"trump"
}
}
},
"should": [
{ "match": {
"type": {
"query": "headline"
}
}}
]}},
"functions": [
{ "boost": 5 },
{
"gauss": {
"versioncreated": {
"origin": "now/d",
"scale": "50w",
"offset": "4w",
"decay": "0.5"
}}}],
"score_mode": "sum"
}
}}
I'm getting this error :-
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [score_function] registered for [params]",
"line": 24,
"col": 20
}
],
"type": "parsing_exception",
"reason": "no [score_function] registered for [params]",
"line": 24,
"col": 20
},
"status": 400
}
You query is a bit wrong. What do you want do by this?
"functions": [
{ "boost": 5 },
If you want to boost it try to use this query
{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"match": {
"keywords": {
"query": "trump"
}
}
},
"should": [
{
"match": {
"type": {
"query": "headline"
}
}
}
]
}
},
"functions": [
{
"gauss": {
"versioncreated": {
"origin": "now/d",
"scale": "50w",
"offset": "4w",
"decay": "0.5"
}
}
}
],
"boost": 5,
"score_mode": "sum"
}
}
}

Resources