elasticsearch - Elastic search v5.5 Scripted Nested Function Scoring -


hi have nested document structure

"question":{     "questionid":{"type":"integer"},     "userid":{"type":"integer"},     "action": {             "type":"nested",             "properties": {               "created": {"type": "date"},               "interactiontype": {"type": "text"},  //values can answer,upvote etc               "userid": {"type": "integer"},               "score":{"type":"long"}               }    ....//other properties   } 

now want scoring of question on several functions. 1 of function is:

  • iterate of every action , type.

actual query little more complex. bascially see query should return me val= sum of scores of (all/script filtered) nested structures.

{   "query": {"function_score": {     "query": {"bool": {"should": [       {"function_score": {"boost_mode": "max",         "query": {"terms": {         "questionid": [           1,2,3,4,5,6,7,8,9,10         ]       }},         "functions": [           {"weight": 0}         ]       }},{         "nested": {           "path": "action",           "query": {"bool": {"must": [             {             "function_score": {               "query": {"script": {                 "script": "doc['userid'].value !=  doc['action.userid'].value"               }},               "functions": [                 {"weight": 0}               ]             }           },{             "function_score": {             "query": {"bool": {"must": [               {"terms": {             "action.userid": [               1100,1200,1300,1400,1500,1600,1700,1800             ]           }}             ]}},             "functions": [               {"script_score": {                 "script": {                   "inline": "double val=0; for(item in doc['action.score']){ val+=score;} return val;"                 }               }}             ]           }}]}}         }       }     ]}},     "functions": [{       "weight": 0}     ],"boost_mode": "sum","score_mode":"sum"    }} }    eg.  question:{     questionid:1,     userid:1,     action:[{         created:null,         interactiontype: "answer",         userid:1100,         score:100},      {        created:null,         interactiontype: "upvote",         userid:1200,         score:10      }] 

should return val=200. returning 100.
might due reason every nested query executing separately.
can please suggest way achieve this?
please don't suggest me index score @ question level going ahead i'll enhancing script filter out nested documents or other complexities in script score inline method.

there property @ nested level name score mode default avg can changed sum cater needs.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -