Question about using Python for User Scripts in 3.20
oderyn opened this issue · comments
sist2 version: 3.2
Platform (Linux or Docker, x86-64 or arm64): Docker
Elasticsearch version: 7.17.9
Love the new user scripts using Python. I am working on one now to help with tagging based on the structure of the filename.
Using the example (https://sist2-python.readthedocs.io/en/latest/examples.html)
Would I post the entire script to the User Script textarea like so:
from sist2 import Sist2Index
import sys
index = Sist2Index(sys.argv[1])
for doc in index.document_iter():
doc.json_data["tag"] = ["hamburger.#00FF00"]
index.update_document(doc)
index.sync_tag_table()
index.commit()
print("Done!")
Or would it look more like this:
for doc in index.document_iter():
doc.json_data["tag"] = ["hamburger.#00FF00"]
index.update_document(doc)
index.sync_tag_table()
index.commit()
print("Done!")
Or something else entirely?
Thanks!
hi, you would set the entire script like in the first example
When I add the example, as-is to to an index, I get the following error:
2023-09-04 13:56:05 [ERROR elastic.c] User script error:
{
"root_cause": [{
"type": "script_exception",
"reason": "compile error",
"script_stack": ["for doc in index.document_ite ...", " ^---- HERE"],
"script": "for doc in index.document_iter():\n doc.json_data[\"tag\"] = [\"hamburger.#00FF00\"]\n index.update_document(doc)\n\nindex.sync_tag_table()\nindex.commit()",
"lang": "painless",
"position": {
"offset": 4,
"start": 0,
"end": 29
}
}],
"type": "script_exception",
"reason": "compile error",
"script_stack": ["for doc in index.document_ite ...", " ^---- HERE"],
"script": "for doc in index.document_iter():\n doc.json_data[\"tag\"] = [\"hamburger.#00FF00\"]\n index.update_document(doc)\n\nindex.sync_tag_table()\nindex.commit()",
"lang": "painless",
"position": {
"offset": 4,
"start": 0,
"end": 29
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid sequence of tokens near ['doc'].",
"caused_by": {
"type": "no_viable_alt_exception",
"reason": null
}
}
}
are you using version 3.2.X ?
The documentation on github is for 3.2 (which is not yet officially released but I believe you can get it using the x64-linux
docker tag)
I am showing version 3.2.0 in my Debug info. Here's the full info:
Label | Value |
---|---|
version | 3.2.0 |
platform | x64_linux_docker |
debugBinary | false |
sist2CommitHash | |
esIndex | sist2 |
tagline | Lightning-fast file system indexer and search tool |
dev | false |
mongooseVersion | 7.7 |
esVersion | 7.17.9 |
esVersionSupported | true |
esVersionLegacy | false |
And here's the image version:
image: simon987/sist2:x64-linux
I did not actually have a screen that looked like that. It was still the user scripts box on the index.
However, I just took it all down and deleted state.db as it was throwing an error.
I've lost my indexes, so will need to rebuild before I can test again, but I am now seeing the screen in your screenshot. I will report back here shortly.
And now it works. :)
I appreciate the assist.
I am definitely glad it was that easy and sorry I had to bug you about it.
Now I gotta try out my own scripts.
This looks like a great new feature!
no worries!