i tested below... but score value is not calculated correctly.
query with range filter is correct.(26)
but query with bool query is not correct. (26.023848)
but range filter is replaced by range query from ES 2.x.
how should i do?
Query with bool query: { "query": { "bool": { "must": [ { "nested": { "query": { "function_score": { "query": { "terms": { "Log_Thing": [ "a", "b" ] } }, "functions": [ { "script_score": { "script": "doc['Log_Thing_Count'].value" } } ], "boost_mode": "replace" } }, "path": "Log_User_Hold", "score_mode": "total" } }, { "range": { "Log_Time": { "from": "2015-11-20 00:00:00", "to": "2015-11-20 23:00:00" } } } ] } } ,"min_score": 26 } Result: { "hits": { "total": 1, "max_score": 26.023848, "hits": [ { "_index": "testnested", "_type": "document", "_id": "1", "_score": 26.023848, "_source": { "Log_User": "gm0604", "Log_Time": "2015-11-20 00:00:00", "Log_User_Hold": [ { "Log_Thing": "a", "Log_Thing_Count": 24 }, { "Log_Thing": "b", "Log_Thing_Count": 2 } ] } } ] } }
Query with Range Filter: { "query": { "nested": { "query": { "function_score": { "query": { "terms": { "Log_User_Hold.Log_Thing": [ "a", "b" ] } }, "functions": [ { "script_score": { "script": "doc['Log_User_Hold.Log_Thing_Count'].value" } } ], "boost_mode": "replace" } }, "path": "Log_User_Hold", "score_mode": "total" } }, "filter": { "range": { "Log_Time": { "from": "2015-11-20 00:00:00", "to": "2015-11-20 23:00:00" } } }, "min_score": 26 } Result: { "hits": { "total": 1, "max_score": 26, "hits": [ { "_index": "testnested", "_type": "document", "_id": "1", "_score": 26, "_source": { "Log_User": "gm0604", "Log_Time": "2015-11-20 00:00:00", "Log_User_Hold": [ { "Log_Thing": "a", "Log_Thing_Count": 24 }, { "Log_Thing": "b", "Log_Thing_Count": 2 } ] } } ] } }
test script is below.
[root@hadoop1 ~]# curl -XPOST localhost:9200/testnested -d '{ "mappings": { "document": { "properties": { "Log_Time": { "type": "date", "format": "YYYY-MM-dd HH:mm:ss" }, "Log_User": { "type": "string", "store": "yes" }, "Log_User_Hold": { "include_in_parent": true, "type": "nested", "properties": { "Log_Thing": { "type": "string", "store": "yes" }, "Log_Thing_Count": { "type": "integer", "store": "yes" } } } } } } }' {"acknowledged":true} [root@hadoop1 ~]# curl -XPUT http://127.0.0.1:9200/testnested/document/1 -d '{ "Log_User": "gm0604", "Log_Time": "2015-11-20 00:00:00", "Log_User_Hold": [ { "Log_Thing": "A", "Log_Thing_Count": 24 }, { "Log_Thing": "B", "Log_Thing_Count": 2 }, { "Log_Thing": "C", "Log_Thing_Count": 6 } ] }' {"_index":"testnested","_type":"document","_id":"1","_version":1,"created":true}