public void IndexUsingAnUrlAsId()
		{
			var id = "http://www.skusuplier.com/products/123?affiliateId=23131#oopsIcopiedAnAnchor";
			var newProduct = new Product
			{
				Id = id,
				Name = "Top Product"
			};
			var response = this.Client.Index(newProduct);

			var productInElasticsearch = this.Client.Source<Product>(i=>i.Id(id));
			Assert.NotNull(productInElasticsearch);
			Assert.AreEqual(productInElasticsearch.Id, id);
			Assert.True(response.IsValid);
		}
		public void MapIdPropertiesForMultipleTypes()
		{
			var settings = new ConnectionSettings()
				.MapIdPropertyFor<ElasticsearchProject>(p => p.LongValue)
				.MapIdPropertyFor<Person>(p => p.Id)
				.MapIdPropertyFor<Product>(p => p.Name);

			var client = new ElasticClient(settings, connection: new InMemoryConnection());

			var project = new ElasticsearchProject { LongValue = 1 };
			Assert.AreEqual(project.LongValue.ToString(), client.Infer.Id<ElasticsearchProject>(project));

			var person = new Person { Id = 2 };
			Assert.AreEqual(person.Id.ToString(), client.Infer.Id<Person>(person));

			var product = new Product { Name = "foo" };
			Assert.AreEqual(product.Name, client.Infer.Id<Product>(product));
		}
예제 #3
0
        public void IndexUsingAnUrlAsIdUsingCustomUrlParameterInSettings()
        {
            var settings = ElasticsearchConfiguration.Settings().SetGlobalQueryStringParameters(new NameValueCollection
            {
                {"apiKey", "my-api-key"}
            });
            var client = new ElasticClient(settings);

            var id = "http://www.skusuplier.com/products/123?affiliateId=23131#oopsIcopiedAnAnchor";
            var newProduct = new Product
            {
                Id = id,
                Name = "Top Product"
            };
            var response = client.Index(newProduct);

            var productInElasticsearch = client.Get<Product>(id);
            Assert.NotNull(productInElasticsearch);
            Assert.AreEqual(productInElasticsearch.Id, id);
            Assert.True(response.IsValid);
        }