简体   繁体   English

建议完成嵌套的用法

[英]SuggestCompletion Nest usage

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. 我正在尝试对某个位置(国家和城市)进行“ SuggestCompletion”查询,我想对这两个字段执行查询。

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

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

Edit 编辑

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

and I also I tried: 我也尝试过:

 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 .....我仍然得到一个空结果

the mapping 映射

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

The support for IndexMany() with wrapped BulkParameters has been removed in NEST 1.0.0 beta 1 NEST 1.0.0 beta 1已删除了对带有包装BulkParameters IndexMany()的支持。

If you want to use a bulk with more advanced parameters you now have to use the Bulk() command. 如果要使用具有更高级参数的批量,则现在必须使用Bulk()命令。

The beta sadly still shipped with the BulkParameters class in the assembly 可悲的是,该测试版仍在程序 BulkParameters包含BulkParameters

This has since been removed in the develop branch. 此后已在开发分支中删除。

So what happens now is that you are actually indexing "bulkparameters``1``" type documents and not "locationinfo" . 所以现在发生的事情是您实际上是在索引"bulkparameters``1``"类型的文档而不是"locationinfo"索引。 So the mapping specified for "locationinfo" does not come into play. 因此,为"locationinfo"指定的映射不起作用。

See here for an example on how to use Bulk() to index many objects at once while configuring advanced parameters for individual items. 有关配置单个项目的高级参数时如何使用Bulk()一次索引许多对象的示例 ,请参见此处的示例

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

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