繁体   English   中英

elasticsearch-php多范围查询不起作用

[英]elasticsearch-php multiple range query not working

我正在为Elasticsearch使用客户端,为Elasticsearch使用客户 ,但是对于多范围查询,我没有得到正确的结果。

我用于查询的正文:

{  
   "index":"locations",
   "type":"portugal",
   "body":{  
      "aggs":{  
         "unique":{  
            "aggs":{  
               "documents":{  
                  "top_hits":{  
                     "size":50
                  }
               }
            },
            "terms":{  
               "field":"cp3"
            }
         }
      },
      "query":{  
         "filtered":{  
            "filter":{  
               "bool":{  
                  "must":{  
                     "range":{  
                        "latitude":{  
                           "gte":41.1373667,
                           "lte":41.1373767
                        },
                        "longitude":{  
                           "gte":-8.631723,
                           "lte":-8.631713
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

结果:

{  
   "took":2,
   "timed_out":false,
   "_shards":{  
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{  
      "total":1,
      "max_score":1,
      "hits":[  
         {  
            "_index":"locations",
            "_type":"portugal",
            "_id":"AVTJ4I0g_vwSgXBDKO-W",
            "_score":1,
            "_source":{  
               "id":222956,
               "latitude":41.0383217,
               "longitude":-8.6317147
            }
         }
      ]
   },
   "aggregations":{  
      "unique":{  
         "doc_count_error_upper_bound":0,
         "sum_other_doc_count":0,
         "buckets":[  
            {  
               "key":199,
               "doc_count":1,
               "documents":{  
                  "hits":{  
                     "total":1,
                     "max_score":1,
                     "hits":[  
                        {  
                           "_index":"locations",
                           "_type":"portugal",
                           "_id":"AVTJ4I0g_vwSgXBDKO-W",
                           "_score":1,
                           "_source":{  
                              "id":222956,
                              "latitude":41.0383217,
                              "longitude":-8.6317147
                           }
                        }
                     ]
                  }
               }
            }
         ]
      }
   }
}

如您所见,结果的纬度不在我指定的纬度范围内。

使用Elasticsearch的Head插件进行测试:

我的查询:

{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "range":{  
                  "latitude":{  
                     "gte":"41.1363671",
                     "lte":"41.1363771"
                  }
               }
            },
            {  
               "range":{  
                  "longitude":{  
                     "gt":"-8.6318828",
                     "lte":"-8.6318728"
                  }
               }
            }
         ],
         "must_not":[  

         ],
         "should":[  

         ]
      }
   },
   "from":0,
   "size":10,
   "sort":[  

   ],
   "aggs":{  

   }
}

结果:(空),此范围内没有记录。

编辑:为我的索引添加了映射:

{     
      "locations":{  
      "aliases":{  

      },
      "mappings":{  
         "portugal":{  
            "properties":{  
               "cp3":{  
                  "type":"long"
               },
               "cp4":{  
                  "type":"long"
               },
               "cpalf":{  
                  "type":"string"
               },
               "id":{  
                  "type":"long"
               },
               "latitude":{  
                  "type":"double"
               },
               "localidade":{  
                  "type":"string"
               },
               "longitude":{  
                  "type":"double"
               }
            }
         }
      },
      "settings":{  
         "index":{  
            "creation_date":"1463675755006",
            "number_of_shards":"5",
            "number_of_replicas":"1",
            "uuid":"C9OO0ig_QyeigqSufK8_dA",
            "version":{  
               "created":"2030199"
            }
         }
      },
      "warmers":{  

      }    
    } 
}

使用以下查询进行测试:

{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "range":{  
                  "latitude":{  
                     "gte": 41.1363671,
                     "lte": 41.1363771
                  }
               }
            },
            {  
               "range":{  
                  "longitude":{  
                     "gt": -8.6318828,
                     "lte": -8.6318728
                  }
               }
            }
         ],
         "must_not":[  

         ],
         "should":[  

         ]
      }
   },
   "from":0,
   "size":10,
   "sort":[  

   ],
   "aggs":{  

   }
}

由于经度和纬度字段为double类型,因此应将其与double进行比较,而将您与string进行比较。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM