Overwrite nested object in Elastic search partial update - elasticsearch

My index structure is
{
"my_index": {
"mappings": {
"blogpost": {
"properties": {
"body": {
"type": "string"
},
"comments": {
"type": "nested",
"properties": {
"age": {
"type": "short"
},
"comment": {
"type": "string"
},
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"name": {
"type": "string"
},
"stars": {
"type": "short"
}
}
},
"tags": {
"type": "string"
},
"title": {
"type": "string"
}
}
}
}
}
}
comments are nested objects. I want to update comment alone. But when I do partial update, ES is merging with existing comment object. I want to replace the existing comment with newer one. Is there anyway, We could configure ES to overwrite instead of merging nested object.

Related

Completion Suggester in Elasticsearch not working

(Using ES 6.7)
I have an index and want to support search-as-you-type feature. For that, I want to try completion suggester but I'm having trouble in reindexing to change the mappings old index.
Here's the old index mappings
{
"old-index": {
"mappings": {
"doc": {
"properties": {
"content": {
"type": "text"
},
"project": {
"type": "keyword"
},
"title": {
"type": "text"
},
"version": {
"type": "keyword"
}
}
}
}
}
}
Here's the new test index mappings
PUT test-completion
{
"mappings": {
"doc": {
"properties": {
"content": {
"type": "text",
"fields": {
"autocomplete": {
"type": "completion",
"contexts": [
{
"name": "project",
"type": "category",
"path": "project"
},
{
"name": "version",
"type": "category",
"path": "version"
}
]
}
}
},
"title": {
"type": "text"
},
"project": {
"type": "keyword"
},
"version": {
"type": "keyword"
}
}
}
}
}
Here's the reindexing query
POST _reindex
{
"source": {
"index": "old-index"
},
"dest": {
"index": "test-completion"
}
}
And here's the query which returns no results
POST test-completion/_search
{
"suggest": {
"autocompletion_suggest": {
"prefix": "part of documentation",
"completion": {
"field": "content.autocomplete",
"fuzzy": {
"fuzziness": "AUTO"
},
"contexts": {
"project": "xyz-project",
"version": "abc-version"
}
}
}
}
}
If the prefix is set to a or b, it returns results outside of context.
Where I'm doing wrong?
https://discuss.elastic.co/t/problem-with-completion-suggester/181695

Elasticsearch mapping parser exception?

I'm trying to create a nested document in Elasticsearch.
Structure:
title,name,comments
comments is a nested document - inside that - Comment & Star_Rating.
Inside Comment, name and address.
Here is the query mentioned below.
PUT /sounduu
{
"mappings": {
"blogpost": {
"properties": {
"title": {
"type": "string"
},
"name": {
"type": "string"
},
"comments": {
"properties": {
"comment": {
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
}
}
},
"star_rating": {
"type": "long"
}
}
}
}
}
}
}
PUT /sounduu/blogpost/1
{
"title": "someh_title",
"name":"soundy",
"comments": {
"comment":"kuu",
[{
"name":"juwww",
"address":"eeeey"
},
{
"name":"jj",
"address":oo"
}]
},
"star_rating":6
}
Error :
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value"
}
],
"type": "mapper_parsing_exception",
"reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value"
},
"status": 400
}
Can anyone help with this?
In your PUT /sounduu/blogpost/1 request you are attempting to treat the "comment" property as both a nested object and a string.
Formatting your request's JSON, you can observe the issue:
{
"title": "someh_title",
"name": "soundy",
"comments": {
"comment": "kuu",
[{
"name": "juwww",
"address": "eeeey"
},
{
"name": "jj",
"address": oo"
}]
},
"star_rating":6
}
You either need to update your mapping to include a "text" property, and move the "comment": "kuu" content accordingly, or omit it from your request to work with your current mapping.
Example here - For me it seems logical to group everything like so:
PUT /sounduu
{
"mappings": {
"blogpost": {
"properties": {
"title": {
"type": "string"
},
"name": {
"type": "string"
},
"comments": {
"properties": {
"text" : {
"type": "string"
},
"name": {
"type": "string"
},
"address": {
"type": "string"
}
}
},
"star_rating": {
"type": "long"
}
}
}
}
}
The indexing request would then look like:
{
"title": "someh_title",
"name": "soundy",
"comments": [
{
"text": "kuu",
"name": "juwww",
"address": "eeeey"
},
{
"text": "kuu2",
"name": "jj",
"address": oo"
}
],
"star_rating":6
}
If you are using elasticSearch higher version, then it is recommended to replace 'string' data type with 'text'. ElasticSearch community has discarded 'string'.
Reformed request should be :
`PUT /sounduu
{
"mappings": {
"blogpost": {
"properties": {
"title": {
"type": "text"
},
"name": {
"type": "text"
},
"comments": {
"properties": {
"text" : {
"type": "text"
},
"name": {
"type": "text"
},
"address": {
"type": "text"
}
}
},
"star_rating": {
"type": "long"
}
}
}
}
}`

Elastic bulk error: failed to parse

I tried posting a _bulk post into elastic search, but it throws:
{
"took": 1,
"errors": true,
"items": [
{
"index": {
"_index": "quick",
"_type": "parts",
"_id": "ACI250-2016",
"status": 400,
"error": {
"type": "mapper_parsing_exception",
"reason": "failed to parse [part]",
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: \"250-2016\""
}
}
}
}
]
}
And here's what I'm trying to post:
POST _bulk
{"index":{"_index":"quick","_type":"parts","_id":"ACI250-2016"}}
{"eMfg":"ACI","part":"250-2016"}
And the map is:
{
"quick": {
"mappings": {
"parts": {
"properties": {
"app": {
"type": "string"
},
"eMfg": {
"type": "string"
},
"fPart": {
"type": "long"
},
"oPart": {
"type": "string"
},
"ofPart": {
"type": "string"
},
"part": {
"type": "long"
},
"price": {
"type": "double"
},
"title": {
"type": "string"
}
}
}
}
}
}
According to your mapping, part has type long and you're trying to send "250-2016". The reason might be that you've sent a document at some point with a part that was coercible to a number, e.g. "250" and now you're trying to send a string and it fails.
The best way is to use the mapping above to define a new index with the correct mapping type (see below) and then you can try your bulk import again.
DELETE /quick
PUT /quick
{
"mappings": {
"parts": {
"properties": {
"app": {
"type": "string"
},
"eMfg": {
"type": "string"
},
"fPart": {
"type": "long"
},
"oPart": {
"type": "string"
},
"ofPart": {
"type": "string"
},
"part": {
"type": "string" <-- change this
},
"price": {
"type": "double"
},
"title": {
"type": "string"
}
}
}
}
}

Update ElasticSearch Mapping type without delete it

I have this mapping type on my Index.
{
"iotsens-summarizedmeasures": {
"mappings": {
"summarizedmeasure": {
"properties": {
"id": {
"type": "long"
},
"location": {
"type": "boolean"
},
"rawValue": {
"type": "string"
},
"sensorId": {
"type": "string"
},
"summaryTimeUnit": {
"type": "string"
},
"timestamp": {
"type": "date",
"format": "dateOptionalTime"
},
"value": {
"type": "string"
},
"variableName": {
"type": "string"
}
}
}
}
}
}
I want to update sensorId field to.
"sensorId": {
"type": "string",
"index": "not_analyzed"
}
Is there any way to update the index without delete and re-mapping it? I don't have to change type of field, I only set "index": "not_analyzed".
Thanks you.
What you can do is make a multi-field out of your existing sensorId field like this with a sub-field called raw which is not_analyzed:
curl -XPUT localhost:9200/iotsens-summarizedmeasures/_mapping/summarizedmeasure -d '{
"summarizedmeasure": {
"properties": {
"sensorId": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}'
However, you still have to re-index your data to make sure all sensorId.raw sub-fields get created.

elasticsearch equivalent of join

I'm new to elastic search and I'm trying to figure out how to do the equivalent of a SQL join. Here are my 2 mappings:
{
"home_panel": {
"mappings": {
"levis": {
"properties": {
"created_at": {
"type": "date",
"format": "dateOptionalTime"
},
"current": {
"type": "string"
},
"event_uuid": {
"type": "string"
},
"panels": {
"properties": {
"action": {
"type": "string"
},
"heightratio": {
"type": "double"
},
"type": {
"type": "string"
},
"url": {
"type": "string"
},
"videourl": {
"type": "string"
}
}
},
"status": {
"type": "string"
},
"updated_at": {
"type": "date",
"format": "dateOptionalTime"
},
"uuid": {
"type": "string"
}
}
}
}
}
}
And:
{
"event": {
"mappings": {
"levis": {
"properties": {
"date": {
"type": "date",
"format": "dateOptionalTime"
},
"event_uuid": {
"type": "long"
},
"name": {
"type": "string"
},
"ticketmaster_game_event_name": {
"type": "string"
},
"ticketmaster_parking_event_name": {
"type": "string"
},
"time": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
}
I'd ideally like to do something like select * from HomePanel InnerJoin Event On home_panel.event_uuid = event.event_uuid so I can see the event in the home panel object. I'm not clear how to do this in elastic search. Is this even possible?

Resources