How to structure index in ElasticSearch - elasticsearch

Let's say I have users index and blogs index. Now I want to enable users to create posts on by blog.
My first thought is that this is how my index should look like:
{
"title": "Blog post title",
"content": "Post text",
"user": {
"username": "lala",
"name": "Johnny",
"birthday": "1991-29-12"
}
}
Which looks good. But what if user changes his name and birthday. Then I need to go through all blog posts and update "user" object?
What if that needs to happen with multiple indexes?
How should I store data like this?

Related

Elasticsearch sorting by relationship

I've defined relationship like this
PUT /my_index/user/1
{
"name": "John Smith",
"email": "john#smith.com",
"dob": "1970/10/24"
"number_of_posts": 4
}
PUT /my_index/blogpost/2
{
"title": "Relationships",
"body": "It's complicated...",
"user": 1
}
How can I sort blogpost by user information like name, email or number_of_posts without using nested field on blogpost, because I don't want to update all blogpost with user = 1 when user change their information. Thanks!

Google API Update Product details

Is there a way to update a product unsing
https://www.googleapis.com/content/v2/SKU/products
or any other scope without inserting all details again in the JSON?
Untill know I understand that as soon I use INSERT and the conditions
"channel": "online",
"contentLanguage": "de",
"offerId": "12345",
"targetCountry": "de",
"condition": "new"
are the same as in one existing product it updates the product.
But I want to avaid to upload every Attribut again and I dont have these data in my Programm in this moment so I would have to GET them each time from Google.
It is possible to update with INSERT but the ID must not be the SKU itself it must contain the JSON ID string(like): "online:de:DE:12345"
So a JSON like:
{
"channel": "online",
"contentLanguage": "de",
"offerId": "online:de:DE:12345",
"targetCountry": "DE",
"price": {
"value": "99.00",
"currency": "EUR"
}
}
Will UPDATE the existing product.

Set ID on creation in elasticsearch

I'm actually starting a new project with elasticsearch, I never used this so I do a lot of research and I just need 1 answer :
How can I choose the ID of an object when I create it ?
For example, when I create this object :
{
"title": "Facebook API Data PHP",
"category": "PHP",
"tags": [
"Facebook",
"API"
],
"test2": 3.5252156144514514521
}
The ID by default is something like this : AVxYqhmCnGpDth4S4vBA
And I want to set the ID when I create the object to something like that object_1
Pass the ID while indexing the data into Elasticsearch. Like
PUT indexName/typeName/object_1
{
"title": "Facebook API Data PHP",
"category": "PHP",
"tags": [
"Facebook",
"API"
],
"test2": 3.5252156144514514521
}

How to Focus Search On One Part of a Document

I'm pretty new to ElasticSearch. I'm using v2.0.0. I would like to know how to focus a search query on one portion of the document in order to answer the question "Get me (a page of 50) People who are a member of Group "Developers".
The document structure of a single person might look like something like this:
{
"_index": "people",
"_type": "employee",
"_id": "8725",
"_source": {
"id": 43470,
"firstName": "John",
"lastName": "Smith",
"groups": [
{
"id": 345,
"name": "Developers"
},
{
"id": 75432,
"name": "Scrummasters"
},
{
"id": 5789,
"name": "UX"
}
]
}
}
So what I want to do is look at the name of each group of each person to see if it matches what I'm looking for and if so, select the whole person. The position of what I'm looking for is obviously not static, and I can't do something simpler like
q=roles:developer
Indeed, I can select employees that are in group Developers by specifying the query string as "q=groups.name:Developers". Indeed, I could also use a wildcard to get anybody in group Admin or Administrators or Admins using "q=groups.name:Admin*"

Search nested arrays in MongoDB documents

I am developing an web app using Codeigniter and MongoDB. Users can save their favorites sounds in as "bookmarks". Each user get one document and then each sound is appended to an array in that document called sounds. Each sound got a set of tags that is also saved to the bookmark. How can I search a users bookmarks in their bookmark document? I want them to be able to search by tags (from the tag array).
This is my MongoDB document:
{
"_id": ObjectId("4f15846a112bf6b725000000"),
"owner": {
"user_id": ObjectId("4f147e1709ab662061000000"),
"session_id": "3424e3155a01e78c50a8498f78cc51d9"
},
"sound_files": [
{
"sound_id": ObjectId("4f1480ff09ab661a61000001"),
"sound_url": "http://s3.amazonaws.com/4c/864ea8e92e6ec4408e248cc9brf008bd/18.wav",
"sound_tags": [
"sound",
"new york",
"cool"
]
},
{
"sound_id": ObjectId("4f1480ff09ab661a61000001"),
"sound_url": "http://s3.amazonaws.com/4c/864ea8e92e6ec4408e248cc9brf008bd/12.wav",
"sound_tags": [
"sound",
"happy",
"ocean"
]
}
],
"total": 1
}
db.col.find({'sound_files.sound_tags':"sound"})
EDIT: Not exactly what OP is looking for apparently. Waiting for a more precise description of the requirement.

Resources