繁体   English   中英

NEST ElasticSearch.Raw.IndiciesCreatePost无法获取正确的索引映射

[英]NEST ElasticSearch.Raw.IndiciesCreatePost does not get correct mappings for index

我正在尝试使用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": {}
   }
}

json字符串的最上方有一个换行符,导致出现奇怪的结果,将其删除给了我预期的行为。

暂无
暂无

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

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