0

I'm using elastic4s to make index in ElasticSearch. My code as following:

var seqBulkDef = SeqBulkCompatibleDefinition
seqBulkDef=seqBulkDef:+request(sha256, parentId, indexMap, ES_INDEX, ES_INDEX_TYPE)
val resp = client.execute (bulk (seqBulkDef)).await(duration)

def request(sha: String, parentId: String, indexMap: Map, index: String, indexType: String): BulkCompatibleDefinition = {
  update(sha) in index / indexType docAsUpsert indexMap parent parentId
}

But it doesn't work for the parentId. How should I modify the syntax please.

Onilton Maciel
  • 3,559
  • 1
  • 25
  • 29
Jack
  • 5,540
  • 13
  • 65
  • 113
  • What's the error? Is it syntatic? How should it behave and what is it actually doing? – Onilton Maciel Oct 29 '15 at 19:15
  • Thanks Onilton, There is no exception, but the problem is that the parentId was ignored, when I searched with has_child or has_parent there was nothing got. – Jack Oct 29 '15 at 19:23
  • `def request` signature seems wrong. Please fix it. You call `request(sha256,parentId,indexMap,ES_INDEX,ES_INDEX_TYPE)`, but the method is `def request(sha: String, parentId: String, indexMap: Map)` – Onilton Maciel Oct 29 '15 at 19:32
  • @OniltonMaciel that's a typo, it can compile and run very well. – Jack Oct 29 '15 at 19:47

2 Answers2

0

You need to add a mapping first to establish the relationship and specify which document type should be the parent of a child type.

In scala4s you would need do do something like this:

client.execute {
  put mapping "places" / "city" parent ("country") 
}

Then you can call

client.execute {
  update("5") in "places" / "cities" docAsUpsert Map("name" -> "São Paulo") parent "2"
}
Onilton Maciel
  • 3,559
  • 1
  • 25
  • 29
  • I tried what you said, but it doesn't work. When I queried "has_parent" I could get some results, but when I queried "has_child" I got nothing. And I found _parent become one of _source fields in child type, this is not correct. – Jack Oct 30 '15 at 16:35
  • So I think this could be a bug of elastic4s. – Jack Oct 30 '15 at 16:36
  • Can you update the question with the code of the query that you are trying to make and that does not return what you expect? What you are getting and what you get instead. – Onilton Maciel Oct 30 '15 at 16:47
-1
update(id).in("places/city").docAsUpsert(write(json)) refresh (RefreshPolicy.IMMEDIATE)
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 1
    Welcome to Stack Overflow. While your code may provide the answer to the question, please add context around it so others will have some idea what it does and why it is there. – Theo Jun 14 '19 at 18:34