2016-05-01 11 views
0

Ich bin derzeit ein wenig kämpfen, wie Sie einen Wert an ein Array in Elasticsearch anhängen.Append an Array in Elasticsearch

Das Dokument sieht in etwa wie folgt aus:

{ 
    "took": 11, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 1, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "iethreads", 
     "_type": "thread", 
     "_id": "AVRk6WRMU5h_y_zwo4s0", 
     "_score": 1, 
     "fields": { 
      "links": [ 
      "[\"https://somelink123.net/thread-714222&page=1\", \"https://somelink123.net/thread-714222&page=2\", \"https://somelink123.net/thread-714222&page=3\", \"https://somelink123.net/thread-714222&page=4\"]" 
      ] 
     } 
     } 
    ] 
    } 
} 

dann betreibe ich das folgende Update-Abfrage

POST _update 
{ 
    "script" : "ctx._source.links+=new_posts", 
    "params" : { 
    "new_posts":"blabliblub" 
    } 
} 

und ich bekomme diese:

{ 
    "took": 11, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 1, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "iethreads", 
     "_type": "thread", 
     "_id": "AVRk6WRMU5h_y_zwo4s0", 
     "_score": 1, 
     "fields": { 
      "links": [ 
      "[\"https://somelink123.net/thread-714222&page=1\", \"https://somelink123.net/thread-714222&page=2\", \"https://somelink123.net/thread-714222&page=3\", \"https://somelink123.net/thread-714222&page=4\"]blabliblub" 
      ] 
     } 
     } 
    ] 
    } 
} 

für mich Also das sieht aus wie Das Array wird wie ein String behandelt und es fügt nur den String hinzu - das ist nicht was ich will.

Wie würde ich den "blabliblub" als neues Element an das Array anhängen?

Antwort

2

Es scheint, dass Ihr links Feld tatsächlich ein Element als String anstelle eines Arrays hat. Um Ihr Update erfolgreich zu machen, muss Ihre Struktur so aussehen:

"fields": { 
     "links": [ 
     "https://somelink123.net/thread-714222&page=1", 
     "https://somelink123.net/thread-714222&page=2", 
     "https://somelink123.net/thread-714222&page=3", 
     "https://somelink123.net/thread-714222&page=4" 
     ] 
    }