Example #1
0
        public void CanScanDiceGames()
        {
            var client = new ElasticSearchClient("ec2-107-22-42-34.compute-1.amazonaws.com", 9500, TransportType.Thrift);

            var startDate = DateTime.UtcNow.AddYears(-10).ToString("o");
            var endDate = DateTime.UtcNow.ToString("o");

            var lastTurnDate = new RangeQuery("LastTurnDate", startDate, endDate, true, true);

            var results = client.Scan<GameDataForList>("dice", new[] {"gameindex"}, lastTurnDate, null, 10, "1m");

            int i = 0;

            foreach (var result in results)
            {
                i++;
                Console.WriteLine("{0}: {1}", i, result.GameId);

                Assert.IsNotNull(result.GameId);

                if(i == 100)
                {
                    return;
                }
            }
        }
Example #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            RangeQuery term = (RangeQuery)value;

            if (term != null)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("range");
                writer.WriteStartObject();
                writer.WritePropertyName(term.Field);
                writer.WriteStartObject();
                writer.WritePropertyName("from");
                writer.WriteValue(term.From);
                writer.WritePropertyName("to");
                writer.WriteValue(term.To);
                writer.WritePropertyName("include_lower");
                writer.WriteValue(term.IncludeLower);
                writer.WritePropertyName("include_upper");
                writer.WriteValue(term.IncludeUpper);
                writer.WriteEndObject();
                writer.WriteEndObject();
                writer.WriteEndObject();
            }
        }
		public void TestRangeQuery()
		{
			var rangefilter = new RangeQuery("age", "22", "25", true, true);
			ConstantScoreQuery query = new ConstantScoreQuery(rangefilter);

			var result = client.Search(index, "type" , query, 0, 5);

			Assert.AreEqual(4, result.GetTotalCount());


			rangefilter = new RangeQuery("age", "22", "25", false, true);
			query = new ConstantScoreQuery(rangefilter);

			result = client.Search(index, "type" , query, 0, 5);

			Assert.AreEqual(3, result.GetTotalCount());

			rangefilter = new RangeQuery("age", "22", "25", false, false);
			query = new ConstantScoreQuery(rangefilter);

			result = client.Search(index, "type" , query, 0, 5);

			Assert.AreEqual(2, result.GetTotalCount());
		}