【问题标题】:NEST ElasticSearch.Raw.IndiciesCreatePost does not get correct mappings for indexNEST ElasticSearch.Raw.IndiciesCreatePost 没有得到正确的索引映射
【发布时间】:2016-01-28 07:25:39
【问题描述】:

我正在尝试使用 NEST 使用原始 json 创建索引,它产生的结果与我使用相同的 json 字符串以交互方式对抗弹性搜索时产生的结果不同。这是一个错误还是我使用不正确?

使用以下命令直接发布到弹性搜索我得到了我想要的索引映射(结果如下所示)

POST /entities
{
"mappings": {
  "sis_item" : 
  {
    "properties":
    {
      "FullPath":
      {
        "type": "string",
        "index":"not_analyzed"
      },
      "Ident":
      {
        "type": "nested",
        "properties":
        {
          "ObjectGuid":
          {
              "type": "string",
              "index":"not_analyzed"
          }          
        }
      }
    }
  }        
}

当我检查索引时的结果: GET /entities/ :(这是正确的)

{
   "entities": {
  "aliases": {},
  "mappings": {
     "sis_item": {
        "properties": {
           "FullPath": {
              "type": "string",
              "index": "not_analyzed"
           },
           "Ident": {
              "type": "nested",
              "properties": {
                 "ObjectGuid": {
                    "type": "string",
                    "index": "not_analyzed"
                 }
              }
           }
        }
     }
  },
  "settings": {
     "index": {
        "creation_date": "1453828294488",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "version": {
           "created": "1070499"
        },
        "uuid": "6_j4vRcqRwiTQw0E6bQokQ"
     }
  },
  "warmers": {}
   }
}

但是,我必须从代​​码中执行此操作,并使用以下代码,我指定的映射最终会出现在设置中,而不是如下所示的映射。

                var createIndexJson = @"
                {
                    ""mappings"": {
                        ""sis_item"" :
                        {
                        ""properties"":
                        {
                            ""FullPath"":
                            {
                            ""type"": ""string"",
                            ""index"":""not_analyzed""
                            },
                            ""Ident"":
                            {
                            ""type"": ""nested"",
                            ""properties"":
                            {
                                ""ObjectGuid"":
                                {
                                    ""type"": ""string"",
                                    ""index"":""not_analyzed""
                                }
                            }
                            }
                        }
                        }
                    }
                }";

var response = _client.Raw.IndicesCreatePost("entities_from_code", createIndexJson);
if (!response.Success || response.HttpStatusCode != 200)
{
  throw new ElasticsearchServerException(response.ServerError);
}

结果(不正确,注意映射嵌套在设置中):

{
 "entities_from_code": {
  "aliases": {},
  "mappings": {},
  "settings": {
     "index": {
        "mappings": {
           "sis_item": {
              "properties": {
                 "FullPath": {
                    "type": "string",
                    "index": "not_analyzed"
                 },
                 "Ident": {
                    "type": "nested",
                    "properties": {
                       "ObjectGuid": {
                          "type": "string",
                          "index": "not_analyzed"
                       }
                    }
                 }
              }
           }
        },
        "creation_date": "1453828283162",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "version": {
           "created": "1070499"
        },
        "uuid": "fdmPqahGToCJw_mIbq0kNw"
     }
  },
  "warmers": {}
   }
}

【问题讨论】:

  • 适用于最新版本的 NEST(2.0.0-alpha2) - 以防万一您想知道。

标签: c# elasticsearch nest


【解决方案1】:

json 字符串的最顶部有一个换行符导致奇怪的结果,删除它给了我预期的行为。

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 2018-05-09
    • 1970-01-01
    • 2019-02-18
    相关资源
    最近更新 更多