I am indexing 85,000 documents with following settings and mapping:
PUT /ap_dataset/
{
"settings": {
"index": {
"store": {
"type": "fs"
},
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"my_english": {
"type": "english",
"stopwords_path": "stoplist.txt"
}
}
}
}
}
PUT /ap_dataset/hw1/_mapping
{
"hw1": {
"properties": {
"docno": {
"type": "keyword",
"store": true
},
"text": {
"type": "text",
"store": true,
"term_vector": "with_positions_offsets_payloads",
"analyzer": "my_english",
"fielddata": true
}
}
}
}
I am using ElasticSearch 5.4. I am trying to replace default scoring with custom scoring in following manner:
GET /ap_dataset/document/_search
{
"query": {
"function_score": {
"query": {
"match": {
"text": "cow"
}
},
"boost_mode": "replace",
"functions": [
{
"script_score": {
"script": "_index['text']['cow'].tf()"
}
}
]
}
}
}
But I am getting the following error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"_index['text']['fox'].tf( ...",
"^---- HERE"
],
"script": "_index['text']['fox'].tf()",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "ap_dataset",
"node": "zhCmVrZgRC-YQU5BOaz49w",
"reason": {
"type": "query_shard_exception",
"reason": "script_score: the script could not be loaded",
"index_uuid": "-TpUstdDQVSZnLwvLKWkPA",
"index": "ap_dataset",
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"_index['text']['fox'].tf( ...",
"^---- HERE"
],
"script": "_index['text']['fox'].tf()",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [_index] is not defined."
}
}
}
}
]
},
"status": 400
}
Any pointers for the problem?
TIA