SuggestCompletion嵌套使用 [英] SuggestCompletion Nest usage

查看:178
本文介绍了SuggestCompletion嵌套使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个位置(国家和城市)做一个SuggestCompletion查询,我想对这两个字段执行查询。

I'm trying to do a SuggestCompletion query for a location (countries and cities), I'd like to perform the query over those two fields.

我的到目前为止,映射如下:

my mapping so far is the following:

var response =  _client.CreateIndex(PlatformConfiguration.LocationIndexName,
                    descriptor => descriptor.AddMapping<LocationInfo>(
                        m => m.Properties(
                            p => p.Completion(s => s
                                .Name(n=>n.CountryName)
                                .IndexAnalyzer("simple")
                                .SearchAnalyzer("simple")
                                .MaxInputLength(50)
                                .Payloads()
                                .PreserveSeparators()
                                .PreservePositionIncrements()).
                                Completion(s=>s.Name(n => n.City)
                                .IndexAnalyzer("simple")
                                .SearchAnalyzer("simple")
                                .MaxInputLength(50)
                                .Payloads()
                                .PreserveSeparators()
                                .PreservePositionIncrements())
                            )));

编辑:
我如何索引元素:

How I'm indexing the elements:

public bool IndexLocations(IList<LocationInfo> locations)

        {
            var bulkParams = locations.Select(p => new BulkParameters<LocationInfo>(p){
                Id = p.Id, 
                Timestamp = DateTime.Now.ToTimeStamp()
            });
            var response = _client.IndexMany(bulkParams, PlatformConfiguration.LocationIndexName);
            return response.IsValid;
        }

修改

查看映射后,我将查询更改为以下内容:

After viewing the mappings I changed my query to the following:

var response = _client.Search<LocationInfo>(location =>
                location.Index(PlatformConfiguration.LocationIndexName).
                    SuggestCompletion("locationinfo", f => f.OnField("countryName").Text(text).Size(1)));

我也试过:

 var response = _client.Search<LocationInfo>(location =>
                location.Index(PlatformConfiguration.LocationIndexName).
                    SuggestCompletion("countryName", f => f.OnField("countryName").Text(text).Size(1)));  

.....我还是得到一个空的结果

.....And I still get an empty result

映射

{
  "locationindex": {
    "mappings": {
      "locationinfo": {
        "properties": {
          "countryName": {
            "type": "completion",
            "analyzer": "simple",
            "payloads": true,
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50
          }
        }
      },
      "bulkparameters`1": {
        "properties": {
          "document": {
            "properties": {
              "city": {
                "type": "string"
              },
              "countryName": {
                "type": "string"
              },
              "countryTwoDigitCode": {
                "type": "string"
              },
              "id": {
                "type": "string"
              },
              "latitude": {
                "type": "string"
              },
              "longitude": {
                "type": "string"
              }
            }
          },
          "id": {
            "type": "string"
          },
          "timestamp": {
            "type": "long"
          },
          "versionType": {
            "type": "long"
          }
        }
      }
    }
  }
}


推荐答案

支持 IndexMany() code> BulkParameters 已在 NEST 1.0.0 beta 1中删除

The support for IndexMany() with wrapped BulkParameters has been removed in NEST 1.0.0 beta 1

如果要使用具有更高级参数的批量,您现在必须使用 Bulk()命令。

If you want to use a bulk with more advanced parameters you now have to use the Bulk() command.

测试版仍然附带了 BulkParameters class 中使用elasticsearch / elasticsearch-net / blob / 1.0.0-beta1 / src / Nest / Domain / Parameters / BulkParameters.csrel =nofollow>

The beta sadly still shipped with the BulkParameters class in the assembly

这已经在开发分支中被删除了。

This has since been removed in the develop branch.

所以现在发生的是你实际索引bulkparameters``1``键入文档,而不是 locationinfo。因此,为locationinfo指定的映射不会起作用。

So what happens now is that you are actually indexing "bulkparameters``1``" type documents and not "locationinfo". So the mapping specified for "locationinfo" does not come into play.

请参阅这里是一个例子关于如何使用 Bulk()来索引许多对象一次配置单个项目的高级参数。

See here for an example on how to use Bulk() to index many objects at once while configuring advanced parameters for individual items.

这篇关于SuggestCompletion嵌套使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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