一个 函数 用来转化esSearch 的range 条件

Posted Terre

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个 函数 用来转化esSearch 的range 条件相关的知识,希望对你有一定的参考价值。

 var filterData =  [
                    {    "component":"filter-criteria",
                        "index":"b04ec5bb5237494da067fed200d4d4a8",
                        "data":{"size":10,
                            "field":"Speed",
                            "fieldType":"数字",
                            "selSimbol":"<",
                            "filter":{
                                "from":"2017-11-13T05:50:22.121Z",
                                "to":"2017-11-13T05:50:22.121Z",
                                "start":0,
                                "end":20,
                                "timeValue":"",
                                "simbolValue":"50"
                                }
                        }
                    },
                    {"component":"filter-criteria",
                    "index":"4ad0d99143b44151b6e8d76d1e85bb9e",
                    "data":{
                            "size":"101",
                            "field":"Time",
                            "fieldType":"时间",
                            "selSimbol":">",
                            "filter":{
                                "from":"2017-11-13T05:50:27.780Z",
                                "to":"2017-11-13T05:50:27.780Z",
                                "start":0,
                                "end":20,
                                "timeValue":
                                "2017-11-13T05:50:27.780Z",
                                "simbolValue":"100"
                                }
                          }
                    }
                            ];
  
  console.log(JSON.parse(JSON.stringify(filterData)));
  var ffdd = JSON.parse(JSON.stringify(filterData));

  function parseFilter(arr){
      
      var rangeFilter = [], range = [];
        for(var kk=0;kk<arr.length;kk++){
            console.log(arr[kk].data.fieldType)
                if(arr[kk].data.fieldType.toString()=="数字"){
                    //alert(2)
                    switch(arr[kk].data.selSimbol){
                        case "<":
                            range[arr[kk].data.field] = {
                                "lt":arr[kk].data.filter.simbolValue
                            }
                            console.log(<的range)
                            console.log(range)
                        break;
                        case ">":
                            range[arr[kk].data.field] = {
                                "gt":arr[kk].data.filter.simbolValue
                            }
                            
                            break;
                    }
                    
                }else if(arr[kk].data.fieldType.toString()=="时间"){
                    //alert(1)
                    switch(arr[kk].data.selSimbol){
                        case "<":
                            range[arr[kk].data.field] = {
                                "lt":arr[kk].data.filter.timeValue
                            }
                            console.log(<的range)
                            console.log(range)
                        break;
                        case ">":
                            range[arr[kk].data.field] = {
                                "gt":arr[kk].data.filter.timeValue
                            }
                            
                            break;
                    }
                }
                var bb={};
                for(var key in range ){
                    if(arr[kk].data.field == key){
                        bb[key] = range[key];
                        rangeFilter.push({
                            "range":bb
                        })
                    }
                }
                
            }
            console.log(range54646546)
            console.log(range)
            //parseRange(range);
            //console.log(parseRange(range));
            console.log(华丽的分割线)
            


            
            
            console.log(*************)
            console.log(sssss)
            var am =  JSON.stringify(rangeFilter);
            var amt = am.replace("[",{).replace("]","}")
            
            console.log(amt)
            

            console.log(sssss)
            console.log(*************)
            return rangeFilter;
        }
    
  function parseRange(data){
     var a={},b={},index=0;
    for (var key in data){
        b[key] = data[key];
        a["range"] = {};
        if(a["range"].hasOwnProperty(key)){
            return;
        }else{
            a["range"] = b;
        }
    }

    return a;
  }

  console.log(parseFilter(ffdd))

 

以上是关于一个 函数 用来转化esSearch 的range 条件的主要内容,如果未能解决你的问题,请参考以下文章

SpringDataJPA融合esSearch

SpringDataJPA融合esSearch

Python的range()函数

6.python基础--range()函数

range()函数

date_range