弹性搜索街道范围搜索 [英] Elastic Search Street Range Search

查看:55
本文介绍了弹性搜索街道范围搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两个字段 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
      }
    }
  }
}

这篇关于弹性搜索街道范围搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆