你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
eric930721
赞同来自:
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
fish_to_sky
要回复问题请先登录或注册
3 个回复
eric930721
赞同来自:
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
{
"size":100,
"_source": {
"includes": [
"title",
"create_time"
]
},
"query": {
"bool" : {
"must" : [{
"script" : {
"script" : {
"inline": "doc['create_time'].getDate().getMonthOfYear() == 11",
"lang": "painless"
}
}
},
{
"script" : {
"script" : {
"inline": "doc['create_time'].getDate().getDayOfMonth() == 11",
"lang": "painless"
}
}
}
]
}
}
}
fish_to_sky
赞同来自:
POST yimi_crm_label_test/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"birthday": {
"value": "2019-10-16"
}
}}]}}}
查询结果
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "yimi_crm_label_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_routing" : "A",
"_source" : {
"birthday" : "2019-10-16"
}}]}}
我就加了一条数据
接下来是按照你的方法,查月份是10
POST yimi_crm_label_test/_search
{
"query":{
"bool": {
"must": [
{
"script":{
"script": {
"source": "doc['birthday'].getDate().getMonthOfYear() == 10"
}}}]}}}
就会报错:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['birthday'].getDate().getMonthOfYear() == 10",
" ^---- HERE"
],
"script": "doc['birthday'].getDate().getMonthOfYear() == 10",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "yimi_crm_label_test",
"node": "Tb8HxaWtQFyQDSpULGxhyw",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['birthday'].getDate().getMonthOfYear() == 10",
" ^---- HERE"
],
"script": "doc['birthday'].getDate().getMonthOfYear() == 10",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "dynamic method [org.elasticsearch.index.fielddata.ScriptDocValues.Dates, getDate/0] not found"
}
}
}
]
},
"status": 400
}