繁体   English   中英

建议完成嵌套的用法

[英]SuggestCompletion Nest usage

我正在尝试对某个位置(国家和城市)进行“ SuggestCompletion”查询,我想对这两个字段执行查询。

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

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())
                            )));

编辑:我如何索引元素:

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;
        }

编辑

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

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)));  

.....我仍然得到一个空结果

映射

{
  "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"
          }
        }
      }
    }
  }
}

NEST 1.0.0 beta 1已删除了对带有包装BulkParameters IndexMany()的支持。

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

可悲的是,该测试版仍在程序 BulkParameters包含BulkParameters

此后已在开发分支中删除。

所以现在发生的事情是您实际上是在索引"bulkparameters``1``"类型的文档而不是"locationinfo"索引。 因此,为"locationinfo"指定的映射不起作用。

有关配置单个项目的高级参数时如何使用Bulk()一次索引许多对象的示例 ,请参见此处的示例

暂无
暂无

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

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