How to show field "name" value by id in results - ES6.3


(Erick Eduardo) #1

I'm trying to do in one query, the 10 most rented, display a text field (name) of another document that are in the same index but are of different types.

Example:
{
"id": 1,
"id_book": 1
"type": "books"
"name": "My book one"
}

{
"id": "7QTwKGQBPPR4nU-GIJQH"
"type": "rented"
"id_book": 1
}

How do I change the id_book by name in my result?


(David Pilato) #2

You can't do join at search time easily in elasticsearch and I'd not recommend doing so.

Better to do join at index time and index things like:

{
  "id": "7QTwKGQBPPR4nU-GIJQH"
  "type": "rented"
  "book": {
    "id": 1,
    "id_book": 1
    "type": "books"
    "name": "My book one"
  }
}

(Erick Eduardo) #3

Thanks David,

But if I need to change the name of the book, the elasticsearch will do this for all records quickly?


(David Pilato) #4

So I guess it was not a real use case but an example as normally a book is pretty much stable once it got printed.

Anyway, it depends. How many instances are going to update? 10? 1000? 10000? 10000000? Depending on that it can time lot of time or nothing.

Would be better to talk about the real use case. But for a use case I have, it takes me around 1 or 2 minutes to index locally 1 million documents (again for my use case). So I'm totally fine having to reindex 1m documents if a value is changing like the book title in your case.

Otherwise, you can look at parent/child feature if you really need it. See the bold text? My advice is to keep things as simple as possible. Parent/child feature comes with some drawbacks so I'd use that only on last resort IMHO.


(Erick Eduardo) #5

Hi,

I have a tracking system that sends data every 180 seconds. Today we have 4000 vehicles.

"_source": {
"plate": "TTT0003",
"userid": 1,
"type": "historical",
"post_date": "2018-06-26T11: 15: 16-03: 00",
"ignition": false,
"created": "2018-06-26T11: 15: 19-03: 00",
"vehicle_id": 6599,
"crawler_id": 14571,
"vehicle": "TTT0003",
"speed": "000,000",
"ignicao_tempo": 120,
"location": {
"lat": "-22.816104",
"lon": "-043.383314"
}
},


(David Pilato) #6

So what is supposed to change in this model?


(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.