弹性搜索街道范围搜索

编程入门 行业动态 更新时间:2024-10-26 06:31:16
本文介绍了弹性搜索街道范围搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有两个字段 Street Number 1 &Elastic Search 中的街道编号 2.我们在弹性搜索中还有一个地址字段,地址是 2 个字段和其他一些字段的组合.所以我们有一个地址:

We have two fields Street Number 1 & Street Number 2 in Elastic Search. We also have an Address field in Elastic Search and Address is a combination of 2 fields with some other fields. So we have an address as:

  • 1604-1612 卡尔弗大厦
  • 1608-1645 公园屋

如果用户使用 1610 进行搜索,则应返回地址.

If the user is searching with 1610 both the address should be returned.

有关如何形成查询的任何帮助?

Any help on how the query can be formed?

推荐答案

这个想法是利用 range 数据类型并将最小和最大街道编号存储在该字段中.

The idea would be to leverage the range data type and store the min and max street number in that field.

在你的映射中,你会有这样的东西:

In your mapping, you'd have something like this:

PUT property_index { "mappings": { "_doc": { "properties": { "street_number_range": { "type": "integer_range" }, "street_name": { "type": "text" } } } } }

然后你可以像这样添加你的两个文档:

Then you can add your two documents like this:

PUT property_index/_doc/1 { "street_number_range" : { "gte" : 1604, "lte" : 1612 }, "street_name": "Calver Building" } PUT property_index/_doc/2 { "street_number_range" : { "gte" : 1608, "lte" : 1645 }, "street_name": "Park House" }

最后,您的查询将如下所示并返回两个文档

Finally, your query would look like this and wold return both documents

GET property_index/_search { "query" : { "term" : { "street_number_range" : { "value": 1610 } } } }

更新

您还可以使用以下查询来搜索范围:

You can also search for a range with the following query:

GET property_index/_search { "query" : { "range" : { "street_number_range" : { "gte": 1600, "lte": 1650 } } } }

更多推荐

弹性搜索街道范围搜索

本文发布于:2023-11-30 00:32:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648126.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹性   街道

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!