使用C#在Elasticsearch中搜索电话号码对象 [英] Searching phone number object in Elasticsearch with C#

查看:176
本文介绍了使用C#在Elasticsearch中搜索电话号码对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个elasticsearch索引,其中包含带有联系文档的电话号码对象. JSON保存如下:

I have an elasticsearch index that contains a phone number object with a contact document. The JSON is saved like this:

"contactId": "fd71b8e0-c3dd-4861-a45d-6917fdb48038",
"phone": { "country": "123",
           "area": "202",
           "number": "4567"
          },
"type": "business"

本文档中用于电话对象的映射的格式为:

The mapping that is used in this document for the phone object is in the form:

,
      "phone": {
        "properties": {
          "area": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "number": {
            "type": "string"
          }
        }
      },

我们正在使用实现Nest的C#应用​​程序查询索引.在应用程序中,我们构造一个Nest SearchDescriptor对象,该对象用作客户端调用的一部分.当用户搜索1232024567之类的字符串时,如何添加到SearchDescriptor中以搜索电话号码?

We're querying the index using a C# application that's implementing Nest. In the application we construct a Nest SearchDescriptor object that is used as part of the client call. How can I add to the SearchDescriptor to search for a phone number when the user is searching for a string like 1232024567?

推荐答案

解决这个问题的一种方法是索引而不是存储完整的数字,即对其进行索引以使其可用于搜索,但不要存储它,因为它可以从您存储的areacountrynumber中重新构造(也可能是索引).

One way in which you could solve this is by also indexing but not storing the complete number i.e. index it to make it available to search on, but don't store it because it can be reconstituted from the area, country and number that you do store (and also probably index).

如果countryareanumber始终可以在索引时间从完整的电话号码中确定,例如始终采用已知格式并遵循某种模式,那么您可以通过索引并存储完整的电话号码来解决此问题,如果只需要countryareanumber进行搜索,然后指定完整的电话号码作为 multi-field ,在对每个countryareanumber的字段进行索引时,使用自定义分析器来提取正确的词项以进行索引.在搜索时,您可以在多字段中使用这些字段来查找countryareanumber值的匹配项.

if country, area and number can always be determined from a complete phone number at index time e.g. always in a known format adhering to a pattern, then you might approach this differently by indexing and storing the complete phone number, and if country, area and number are only needed for search, then specifying the complete phone number as a multi-field, using a custom analyzer at index time on a field for each of country, area and number to extract the correct terms for indexing. at search time, you can then use these fields within the multi-field to find matches on country, area and number values.

这篇关于使用C#在Elasticsearch中搜索电话号码对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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