I have a collection named templates. It has a field 'sec_1' which is an array of objects with properties 'name' and 'des' both of type string. Now I'm using elastic search and when I try to execute a query that matches only title fields I get an error saying the sec_1 field is not nested. Upon checking the mappings here is what I get mapping type of sec_1 is text.
I checked online and saw the fix was to modify the mapping. I created a new index like:
`curl base_url/new_index_name
{
"mappings":
{"properties": {
"sec_1": {
"type":
"nested","properties": {
"name": { "type": "text" },
"des": { "type": "text" }
}
}
}
}
}
and then reindexed like this:
curl base_url/_reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index"
}
}`
First request is successful, the second one fails with this error:
{
"index": "new_index",
"type": "_doc",
"id": "be5123a4-d0e8-4d7b-a8f1-42f31d37fe55",
"cause": {
"type": "mapper_parsing_exception",
"reason": "object mapping for [sec_1] tried to parse field [null] as object, but found a concrete value"
},
"status": 400
},
I don't understand why this is happening and what I'm doing wrong. Please help. I do not know much about elastic search, I've looked for solutions online, tried chatgpt too but the same steps appear. I'm finding the reason for this error is that sec_1 is not nested type but I've checked in database it is an array of objects. What else could be wrong?
I tried creaing new index but cannot do that and without new index my search query cant function properly
Related
I'm writing a programme to create a page under a Notion database using the API, but am having trouble getting the multi-select property to work
This is what I have written in properties { } (lines 67-76 of the code in my index.js in my repo)
"multi-select": [
{ "name": tag1},
{ "name": tag2}
],
This is in an async function where tag1 and tag2 are string variables
But when I run the code I get the following error:
'code: validation_error', message: 'body failed validation. Fix one:\n' + .... {"object":"error", ...
(It's too long to paste but that's the gist. I screenshotted the full error here.)
The code works perfectly when I comment these lines out.
I see no reason why this shouldn't work, so I suspect I have done something wrong in my set-up elsewhere, since I'm quite new to coding. The full repo is here - it's not long
Grateful for what I'm sure is probably a quick fix - thank you very much :)
There's a couple things going on with how you're trying to define the the multi select property:
It should be multi_select not multi-select
The body should be an object with an array of options, not just an array. I think you've copied some stuff from an API response which looks a little different.
"Tags": {
"multi_select": {
"options": [
{
"name": tag1,
"color": "red"
},
{
"name": tag2,
"color": "gray"
}
]},
The format for the JSON above seems incorrect, here's an updated one if you're copy/pasting:
{
"Tags": {
"multi_select": {
"options": [
{
"name": "tag1",
"color": "red"
},
{
"name": "tag2",
"color": "gray"
}
]
}
}
}
I am making a db query upon hitting a POST API endpoint. The query needs to update the Json column in my networks table, which only has 3 columns (id, name, and json). I need to specifically update the coreEssentials array with another value, so I have been using the set 'json' = ? SQL query where I paste in the entire column with my changes in the specific field and it works (manually in the db). The only issues are, I need to do make a SQL call to SELECT the json column for a specific id first, (long story, but a backend application generates some data into the JSON (the coreEssentials key/object I need to update) then puts it into the data, then after I need to update).
I was doing this manually in my Postgresql GUI (DBbeaver) and my query simply looks like this:
update network set "json" = '{
"uid": "randomUid",
"etag": "randomEtag",
"name": "randomNameAgain",
"state": "PENDING",
"Type": "ABC",
"version": 1,
"dealerId": "random_uuid",
"Param": {
"AreaId": 0,
"AreaIdStr": "0.0.0.0",
"DeadInterval": 0,
"HelloInterval": 0
},
"networkData": {
"tic": "311",
"toe": "980",
"tac": "201",
"tac_id": "201",
"timeZone": null
},
"production": false,
"customerName": "random_name",
"IPPool": "0.0.0.0/32",
"customerEmail": "random#email.com",
"coreEssentials": [ ],
"deployment": "A"
}'
coreEssentials starts out as an Empty array but I need to set it to this:
[{
"version": 1,
"component": "purple",
"instanceId": "1"
},
{
"version": 1,
"component": "gray",
"instanceId": "1"
},
{
"version": 1,
"component": "blue",
"instanceId": "1"
} ]
I'm using a Node JS backend with pg-promise (Postgresql) library. Can anyone give me advice how to do this query?
I just set coreEssentials array to the data object returned from the first SQL query like #vitaly-t suggested :D
I cannot find any info if there is any limitations for dojo treegrid JSON store. Here is my simple store. It works perfect but fails if it has thousands of items. So is there a limit for number of items or childItems? Or is there a limit for JSON object size?
{
"identifier": "id",
"label": "name",
"items": [
{
"id": "id1",
"type": "year",
"year": "2018",
"childItems": [
{
"id": "id0",
"projname": "Project 1"
},
{
.....
}
]
},
{
.....
}
]
}
Dojo treegrid mostly shows this error message when it finds multiple items with the same id, so you want to make sure all "id" attributes in your "items" list have unique value. In my test setup I was able to load more than 20000 rows so most probably you have malformed data. Supply following option to grid to log any fetch related errors:
onFetchError: function(err, req){
console.log(err);
}
Hope it helps.
I'm trying to get the latest records, grouped by the field groupId, which is a String like "group_a".
I followed the accepted answer of this question, but I've got the following error message:
Fielddata is disabled on text fields by default. Set fielddata=true on [your_field_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.
In the Elasticsearch docs is written:
Before you enable fielddata, consider why you are using a text field for aggregations, sorting, or in a script. It usually doesn’t make sense to do so.
I'm using a text field, because groupId is a String. Does it make sense to set fielddata: true if I want to group by it?
Or are there alternatives?
Using "field": "groupId.keyword" (suggested here) didn't work for me.
Thanks in advance!
The suggest answer with .keyword is the correct one.
{
"aggs": {
"group": {
"terms": {
"field": "groupId.raw"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1,
"sort": [
{
"timestamp (or wathever you want to sort)": {
"order": "desc"
}
}
]
}
}
}
}
}
}
with a mapping like that:
"groupId": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
I know this is a very simple and common question; I've already read some Q/A but I can't figure out how to solve my problem.
I have this short json from an AJAX call that execute a SPARQL query:
{
"head": {
"vars": [ "name" , "email" ]
} ,
"results": {
"bindings": [
{
"name": { "type": "literal" , "value": "Name Surname" } ,
"email": { "type": "literal" , "value": "name.surname#email.com" }
}
]
}
}
I'm searching name and email of a single user of the application, so
the result should be always made up of a single element.
What I want to retrieve is the "name" of the user.
I tried something like:
response["name"].value
//or
response[0]["name"]
//or
response.name
but always wrong.
How can I get the name value? Thanks to everyone who will help.
Try this
response.results.bindings[0].name.value
response.results.bindings[0].email.value
Update
Example
You can check out the fiddle created here
http://jsfiddle.net/uqxp4j73/
The code for this is as under
var x='{ "head": { "vars": [ "name" , "email" ] } , "results": { "bindings": [ { "name": { "type": "literal" , "value": "aadil keshwani" } , "email": { "type": "literal" , "value": "name.surname#email.com" } } ] }}';
obj = JSON && JSON.parse(x) || $.parseJSON(x);
console.log(obj);
console.log(obj["results"]["bindings"][0]["name"]["value"]);
alert(obj["results"]["bindings"][0]["name"]["value"]);
Hope this helps :)
In JSON, you always have to provide the full path to the property you like to reach. Assuming you have stored the parsed JSON in variable response, the following paths will get you corresponding value.
response.results.bindings[0].name.value for name
response.results.bindings[0].email.value for email
Recommend you to go through http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/ to get basic concepts of JSON.