groovy - Elasticsearch: storing tags without duplicates -


i want store tags in documents in way won't have duplicates.

my documents have tags field defined as:

... "tags": { "type": "string" } ... 

i add tags tags field python:

es.update(index=es_index, doc_type=es_doc_type, id=user_id, body=doc) 

my update document:

doc = {   "script": {     "lang": "groovy",     "inline": "ctx._source.tags.addall(tags)",     "params": {       "tags": [         "c#",         "winforms",         "type-conversion",         "decimal",         "opacity"       ]     }   } } 

this works, tags potentially duplicated.

i want deduplicate tags before storing them. want tags field act set.

here's tried (based on answer: https://stackoverflow.com/a/17465831/318557)

... "inline": "ctx._source.tags.addall(tags); ctx._source.tags.unique();", ... 

but has no effect.

is there groovy solution that? or maybe support elasticsearch storing sets?

i dont think groovy problem. checking correct objects?

i have following document indexed:

{     "_index": "script",     "_type": "test",     "_id": "av2jd1zxm1enu8lqyozs",     "_score": 1,     "_source": {         "tags": [             "tag1",             "decimal"         ]     } } 

and call:

curl -x post \   http://127.0.0.1:9200/script/test/av2jd1zxm1enu8lqyozs/_update \   -d '{   "script": {     "lang": "groovy",     "inline": "ctx._source.tags.addall(tags); ctx._source.tags.unique();",     "params": {       "tags": [         "c#",         "winforms",         "type-conversion",         "decimal",         "opacity",         "aaa",         "aaa"       ]     }   } }' 

result:

{     "_index": "script",     "_type": "test",     "_id": "av2jd1zxm1enu8lqyozs",     "_score": 1,     "_source": {         "tags": [             "tag1",             "decimal",             "c#",             "winforms",             "type-conversion",             "opacity",             "aaa"         ] } 

so groovy works fine here, check rest client. can event try reassign collection:

"inline": "ctx._source.tags = ctx._source.tags.unique(); ctx._source.tags += tags.unique();", 

maybe more problem python code?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -