ElasticSearch - Find matches with exact value - database

I'm new working with elastic search and I'm trying to make a simple query work. I'm using elasticseach 2.3. I can't use a newer version I'm limited by another technology I'm using.
Basically I have News stored in the database with a title, a source and a publication date.
The query I'm trying to make should search for all the news that contain a certain keyword, come from some sources A or B and have a publication date in the range given.
So far I have this:
{
"query":{
"bool":{
"must":[
{
"bool":{
"should":[
{
"match":{
"source":"SOURCE_A"
}
},
{
"match":{
"source":"SOURCE_B"
}
},
{
"match":{
"title": "keyword"
}
}
]
}
}
],
"filter":{
"range":{
"publication_date":{
"gte":"DATE_FROM",
"lte":"DATE_TO"
}
}
}
}
}
}
The problem is that if a given source starts exactly the same as another source (for example: "SOURCE" and "SOURCE ABC") they are both included in the result. I would like to match exactly the same source.
Can anyone point me in the right direction?
Thanks!
The index is being created by Django Haystack but given its limitations I need to query the database myself. The index mapping is the following:
{
"myindex": {
"mappings": {
"modelresult": {
"properties": {
"django_ct": {
"type": "string",
"index": "not_analyzed",
"include_in_all": false
},
"django_id": {
"type": "string",
"index": "not_analyzed",
"include_in_all": false
},
"id": {
"type": "string"
},
"publication_date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"source": {
"type": "string",
"analyzer": "ascii_analyser"
},
"summary": {
"type": "string",
"analyzer": "ascii_analyser"
},
"text": {
"type": "string",
"analyzer": "ascii_analyser"
},
"title": {
"type": "string",
"analyzer": "ascii_analyser"
},
"url": {
"type": "string",
"analyzer": "ascii_analyser"
}
}
}
}
}
}

Related

Azure Logic App Partition key [X] is invalid with COsmos Db

I need to save JSON parsed data to Cosmos Db, HTTP trigger works as it should as well as parsing but getting Partition key [my_dynamic_key_value] is invalid.
Did anyone have a similar issue?
I have found this article link but still getting the same error.
Thanks
EDIT 1
This is the flow for adding item to DB
Schema:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"Groups": {
"type": "array",
"items": {
"type": "string"
}
},
"JobName": {
"type": "string"
},
"Link": {
"type": "string"
},
"MinSalary": {
"type": "string"
},
"MaxSalary": {
"type": "string"
},
"Hours": {
"type": "string"
},
"WorkPattern": {
"type": "string"
},
"Details": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"Detail": {
"type": "string"
}
},
"required": [
"Name",
"Detail"
]
}
}
},
"required": [
"id",
"Groups",
"JobName",
"Link",
"MinSalary",
"MaxSalary",
"Hours",
"WorkPattern",
"Details"
]
}
}
Here is a response:
{
"code": "BadRequest",
"message": "Partition key [1bb2d44f-a066-4fa8-8a78-0cdcea1a756c] is invalid.\r\nActivityId: 345f9a99-534b-40cb-9dc0-9863dc8c90f5, \r\nRequestStartTime: 2020-04-28T08:04:46.8249255Z, RequestEndTime: 2020-04-28T08:04:46.8249255Z, Number of regions attempted:1\r\n, Microsoft.Azure.Documents.Common/2.10.0"
}
You need to set the partition key in the double quotes. Refer to sample screen shot below

Loop each element of a stored Procedure ResultSet in PowerAutomate(SQL Server)

I want to add an action to my Flow which loops through all the items in a ResultSet and adds them to an SQL Server Table.
The Result set is retrieved using a stored procedure like shown here:
the return values look like this:
I can access the "ReturnCode" if using an SQL Server "Insert Row" Action like this:
but I have no idea how to perform the insert action for each element in this ResultSet, since I cannot access it when using a foreach Action:
forgive me if the solution is obvious, I'm new to PowerAutomate and can't quite figure out how return types are processed. Also if any required information is missing, please tell me so I can add it here.
Your response looks like a JSON to me so, using that you could use the "Parse JSON" cction in flow to create an "object" that you can use its properties.
For example:
Your JSON response:
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
}
When you paste that in the "Generate from Template" dialog and click "Done", you will get a schema like the one below:
{
"type": "object",
"properties": {
"glossary": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"GlossDiv": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"GlossList": {
"type": "object",
"properties": {
"GlossEntry": {
"type": "object",
"properties": {
"ID": {
"type": "string"
},
"SortAs": {
"type": "string"
},
"GlossTerm": {
"type": "string"
},
"Acronym": {
"type": "string"
},
"Abbrev": {
"type": "string"
},
"GlossDef": {
"type": "object",
"properties": {
"para": {
"type": "string"
},
"GlossSeeAlso": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"GlossSee": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
Depending on the JSON response you, you might want to rename a few properties in your schema or even change their type - that will help you to see the properties in you next action:
EDIT: Your objects of type array (from the schema) can be used in the Foreach loop

ElasticSearch mapping for dynamic fields

I have an index with the name 'dev-steps',
mapping for this index:
{
"dev-steps": {
"mappings": {
"steps": {
"properties": {
"cId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data": {
"properties": {
"ui034": {
"type": "long"
},
"ksms5": {
"type": "long"
},
"ui0tg": {
"type": "long"
},
"vcw5d": {
"type": "long"
}
}
},
"uId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
I see a problem, any time when I add new value to the field 'data', that add a new property to the mapping; how I can create a dynamic mapping?
You can achieve this by adding a dynamic template to your index mapping (Elasticsearch Reference: Dynamic templates).
Thinking I found an answer to my question
Too many fields bad for elasticsearch index?
and sure I found in elasticsearch docs
https://www.elastic.co/blog/found-beginner-troubleshooting#keyvalue-woes

ElasticSearch scripting - get unsorted array order

I have the following schema, where spending is an array.
{
"mappings": {
"entityName": {
"dynamic": "false",
"properties": {
"id": { "type": "string", "index": "not_analyzed" },
"spending": {
"dynamic": "false",
"type": "object",
"properties": {
"start": { "type": "date", "index": "not_analyzed" },
"end": { "type": "date", "index": "not_analyzed" },
"amount": { "type": "float", "index": "not_analyzed" }
}
}
}
}
}
}
Everything works great until I try to access spending.amount in a groovy map script by its index with doc['spending.amount'].values[i] - it returns a different element and the doc['spending.amount'].values is actually sorted.
So, the question is: how do I access the original (unsorted) array? I looked into this and this but whenever I used ctx._source all I got was
No such property: ctx for class: 0c55d8cb3fce09491241ef9d60297789e92dee68
Thanks.

Angular schema form access Object with Arrays from Form

I have a scenario where i need to display arrays in side a named object like this:
"actions": {
"singleSelection": [
{
"chartable": false,
"label": ""
}
]
}
I have accomplished it with the following schema:
"schema": {
"type": "object",
"title": "smart_report",
"properties": {
"actions": {
"title": "Actions",
"type": "object",
"properties": {
"singleSelection": {
"title": "Action: Single selection",
"type": "array",
"maxItems": 10,
"items": {
"type": "object",
"properties": {
"field": {
"title": "Field name",
"type": "string"
},
"label": {
"title": "Label",
"type": "string",
"description": "Label will be used for column name."
},
"chartable": {
"title": "Chartable",
"type": "boolean"
}
}
}
}
}
}
}
Now am trying to set the 'notitle' flag on 'actions' in from and trying to access the properties of 'actions', but its not working as expected:
{
"key": "actions",
"notitle": true,
"properties": {
"key": "singleSelection",
"notitle": true,
"startEmpty": true
}
},
I still see title for actions as well for 'singleSelection' and 'stratEmpty' is also not set.
If you remove the titles from the schema, as well as using the notitle attribute it should work.
(In case you remove the title, but do not use the notitle attribute, the title will be displayed with the same name as the key).

Resources