[英]How to sort by a string date in ElasticSearch using ElasticSearch.js
[英]How can I sort price string in ElasticSearch?
在弹性搜索中将Price
作为关键字保留不是一个好主意,最好的方法是将price
映射为弹性搜索中的scaled float
,如下所示:
新映射:
PUT [index_name]/_mapping
{
"properties": {
"price2": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
要解决您的问题,您可以添加新映射并将您的值从string
转换为numeric
:
按查询更新:
POST [index_name]/_update_by_query
{
"query": {
"match_all": {}
},
"script": {
"source": "ctx._source['price2'] = ctx._source['price'].replace(',','')"
}
}
此查询会将您的keyword
值转换为string
并将其映射到名为price2
另一个字段中,然后您需要有一个ingest pipeline
来执行对新条目的处理:
摄取管道:
POST _ingest/pipeline/_simulate
{
"pipeline": {
"processors": [
{
"script": {
"description": "Extract 'tags' from 'env' field",
"lang": "painless",
"source": "ctx['price2'] = ctx['price'].replace(',','')"
}
}
]
},
"docs": [
{
"_source": {
"price": "5,000.00"
}
}
]
}
您需要删除_simulate
并将此ingest pipeline
添加到您的索引中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.