Beispiel #1
0
        public void Has_Dynamic_Details()
        {
            string mySpecialField = "special things";
            var product = new Product();

            product.Details.MySpecialField = mySpecialField;

            Assert.Equal(product.Details.MySpecialField, mySpecialField);
        }
Beispiel #2
0
		public async Task IndexAsync(Product product)
		{
			Console.WriteLine(string.Format("Indexing product {0}", product.Id));
			var dto = Mapper.Map<ProductDTO>(product);

			//Update the variants partially, using the script
			//This method isn't going to support n-recursive product variants
			foreach (var variant in dto.Variants)
			{
				var variantResponse = await _client.UpdateAsync<ProductDTO>(body => body
					.Id(dto.Id)

					.Params(pms => pms.Add("new_variant", variant))
					.Script(Transactional.Scripts.update_variants)
					.Lang("groovy")

					.Index("products")
					.Upsert(dto)
					.Type<ProductDTO>()
				);

				if (!variantResponse.ConnectionStatus.Success)
				{
					Console.WriteLine(Encoding.Default.GetString(variantResponse.ConnectionStatus.Request));
					throw variantResponse.ConnectionStatus.OriginalException;
				}
			}

			//Update the rest of the document
			dto.Variants = null;
			var indexResponse = await _client.UpdateAsync<ProductDTO>(body => body
				.Id(dto.Id)
				.Doc(dto)
				.Index("products")
				.Type<ProductDTO>()
			);

			if (!indexResponse.ConnectionStatus.Success)
			{
				Console.WriteLine(Encoding.Default.GetString(indexResponse.ConnectionStatus.Request));
				throw indexResponse.ConnectionStatus.OriginalException;
			}
		}