elastic search - how to query the child resource - elasticsearch

I have a resource
GET /parents/{Id}
this one I can see the alias in elastic search, I am able to retrieve data in ES by doing this : (GET parents_alias/parent/5/)
However with this resource
2/
For /parents/{Id}/comment/{commentId} I do not have an alias
I do not know how to query in ES in order to get comment
any idea?

If you are trying to create a parent child association in elasticsearch I believe you need to first create the parent-child mapping as explained here - https://www.elastic.co/guide/en/elasticsearch/guide/master/parent-child-mapping.html
Also you can get parent records if you know child details and vice versa.
More details here - https://www.elastic.co/guide/en/elasticsearch/guide/master/has-child.html
https://www.elastic.co/guide/en/elasticsearch/guide/master/has-parent.html

Related

Suggest Feature in Elastic Search

I am trying to implement suggest feature - Suggest Usage | Elasticsearch .NET Client [8.4] | Elastic 1 for handling misspelled words in my search implementation.
My search query is executed across multiple indices but while trying to use the suggest functionality , i am running into failures due to unmappaed fields.
Suppose i have an index named People which has a field - "name". Another index named news which has a field named - "title". My query was executed across both indices at the same time and search query had rules defined for both name and title fields. But while using suggest, i only want to return suggestions for name field in person index as part of the same query. As a result of this my news index is returning a failure that no mapping found for field name.
Is there a work- around in the suggest functionality via which i can specify an index name for the field mentioned in suggest - Suggest Usage | Elasticsearch .NET Client [8.4] | Elastic 1 OR can i ignore unmapped fields and continue to return search results from the other index (news) without returning any suggestions for misspelled words for that index.

Does updating Elasticsearch indices requires updating Kibana index pattern?

I am using Elasticsearch and Kibana as plugin to view the data in the indices. I am using Kibana's DevTools to send commands for adding/deleting/updating indices etc.
I want to add a field to a certain text property so it will have a keyword field to be able to both make a full text searches and aggregate using this property.
1) Does a change like that means I need to update Kibana's index pattern as well?
2) I have read the ElasticSearch's docs on PUT Mappings and know how to use it to update the indices themselves, but I don't know how to update the index patterns.. I read the same API should be used to update it, but I don't know how to see the index pattern's original mapping in order to update it.
Yes, if you change the index mapping in ES, then you need to go in Kibana and refresh the related index patterns.
Right now, you need to go inside Kibana (Management > Index patterns), select the index pattern, and press the "Refresh" button at the top right of the window in order to pick up the mapping changes.
Also note that if you updated some text fields in order to have a keyword sub-field, you'll also need to call the _update_by_query API on your index in order to reindex the changed field in all your documents

Updating a record by query in ElasticSearch using olivere/elastic in google go

I am using olivere/elastic library for elasticsearch in my go app . I have list of values for a particular field (say fieldA) of elasticsearch document. I want to update a particular field of all document by searching on field fieldA .
This : Updating a record in ElasticSearch using olivere/elastic in google go
explains the update part. But in my case in don't have Id of documents to be updated . So, either i can make search call to retrieve document ids and then update them , or is there another way am missing? Thanks in Advance.
If you need to update a list of documents, you can use the Update By Query API. The unit tests give you a hint about how the syntax looks like. However, if you have individual values for individual documents, I guess there's no other way than updating them one by one. The fastest way to achieve that is by using the Bulk API.

elasticsearch copy field when indexing

I would like to create a one to many relashanship for the purpose of aggregations.
The "join" will be according to a field called "common_id":
When I create the first document belonging to the same group I would like to use it's flakeId (it's _id) as the common_id.
When adding other document belonging to the same group I would like to explicitly set the common_id to have the same value as the first document I added. This can be done by my app since my application will know the common_id of the first element.
My problem is with the first document:
How can i tell elasticsearch to copy the _id into common_id in a single call to elastic (I know I can do it using update script, or using two calls one for index and one for update... but this requires two requests instead of one).
I would like a simple syntax for this.
thanks

Not all results included with parent-child query

I'm trying to query ES (v. 2.2.0) and get child documents with their parents.
My Structure: post is a parent of campaignPost; campaignPost is a child of post.
And here is mapping for campaignPost:
http://pastebin.com/iAaAzdp3
Now in my index I've got 20 posts and 10 campaignPosts mapped to 10 of existing posts. The problem is that I'm expecting 10 records in the result but I've got only 4! Here is how I query ES:
http://pastebin.com/1vWwbMA2
Thanks for any suggestions!
I had a similiar problem with parent child relationship where my child type was parent of another type. Problem relied on routing parameter what was unsuitable for my granchildren. According to ES documentation my _routing parameter had to point on grandfather type.
The parent parameter is used to link the children with its parent, but the routing parameter ensures that it is stored on the same shard as its parent and grandparent. The routing value needs to be provided for all single-document requests.
Try to set your _routing parameter properly and let me know if it helps.

Resources