Hi everyone,
Right now I'm stuck with keeping old logic sort from MySQL to Elastic.
In MySQL, I have a project table with field 'projectName'. When user search project using keyword, I use Match function with Boolean Mode in MySQL to sort result.
When move it to Elastic, I want to keep that logic with code as below:
"_script": {
You need to change the mapping and reindex your data and change the field projectName to keyword or add a subfield in the mapping with the keyword datatype.
But ideally, if possible, you should compute this at index time instead of running the script at search time.
I'm not sure I understand the use case so sharing some practical example would be helpful to give you may be a better answer.
Thanks for response. My English it limit so you may can not understand my case.
Can not re-index because 'keyword' is what user input and it change every time user search for bunch of projects. It must be search time because it dynamic. I just want the projects have projectName MATCH with keyword have high position in search result.
I already think about your solution, but I need all project not match keyword to.
MATCH just use for sort order, not just match keyword will return. Project have name not match with 'keyword' have lower position in result. Sorry, the logic here have a little bit weird.
If I'm misunderstanding, please provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.
A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.