Skip to content

Commit

Permalink
Add index.queries.cache.enabled setting to IndexSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam committed Jun 14, 2016
1 parent d48591a commit 29e0e6e
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 21 deletions.
Expand Up @@ -11,11 +11,11 @@ public abstract class IsADictionaryBase<TKey, TValue> : IIsADictionary<TKey, TVa
private IDictionary Self => BackingDictionary;

protected IsADictionaryBase() { this.BackingDictionary = new Dictionary<TKey, TValue>(); }
//protected IsADictionaryBase(Dictionary<TKey, TValue> backingDictionary) { this.BackingDictionary = backingDictionary; }

protected IsADictionaryBase(IDictionary<TKey, TValue> backingDictionary)
{
this.BackingDictionary = backingDictionary != null
? new Dictionary<TKey, TValue>(backingDictionary)
this.BackingDictionary = backingDictionary != null
? new Dictionary<TKey, TValue>(backingDictionary)
: new Dictionary<TKey, TValue>();
}

Expand Down Expand Up @@ -79,4 +79,4 @@ protected IsADictionaryBase(IDictionary<TKey, TValue> backingDictionary)
}


}
}
@@ -0,0 +1,24 @@
namespace Nest
{
public interface IQueriesCacheSettings
{
/// <summary>
/// Whether the query cache is enabled. <c>True</c> by default.
/// </summary>
bool? Enabled { get; set; }
}

public class QueriesCacheSettings : IQueriesCacheSettings
{
public bool? Enabled { get; set; }
}

public class QueriesCacheSettingsDescriptor : DescriptorBase<QueriesCacheSettingsDescriptor, IQueriesCacheSettings>, IQueriesCacheSettings
{
bool? IQueriesCacheSettings.Enabled { get; set; }

/// <inheritdoc/>
public QueriesCacheSettingsDescriptor Enabled(bool enabled = true) =>
Assign(a => a.Enabled = enabled);
}
}
23 changes: 23 additions & 0 deletions src/Nest/IndexModules/IndexSettings/Queries/IQueriesSettings.cs
@@ -0,0 +1,23 @@
using System;

namespace Nest
{
public interface IQueriesSettings
{
IQueriesCacheSettings Cache { get; set; }
}

public class QueriesSettings : IQueriesSettings
{
public IQueriesCacheSettings Cache { get; set; }
}

public class QueriesSettingsDescriptor : DescriptorBase<QueriesSettingsDescriptor, IQueriesSettings>, IQueriesSettings
{
IQueriesCacheSettings IQueriesSettings.Cache { get; set; }

/// <inheritdoc/>
public QueriesSettingsDescriptor Cache(Func<QueriesCacheSettingsDescriptor, IQueriesCacheSettings> selector) =>
Assign(a => a.Cache = selector.Invoke(new QueriesCacheSettingsDescriptor()));
}
}
Expand Up @@ -95,11 +95,9 @@ public interface IDynamicIndexSettings : IIsADictionary<string, object>

public class DynamicIndexSettings : IsADictionaryBase<string, object>, IDynamicIndexSettings
{
public DynamicIndexSettings() : base() { }
public DynamicIndexSettings() { }

public DynamicIndexSettings(IDictionary<string, object> container) : base(container) { }
public DynamicIndexSettings(Dictionary<string, object> container)
: base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value))
{ }

/// <inheritdoc/>
public int? NumberOfReplicas { get; set; }
Expand Down
22 changes: 14 additions & 8 deletions src/Nest/IndexModules/IndexSettings/Settings/IndexSettings.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Nest
Expand All @@ -7,8 +8,8 @@ namespace Nest
public interface IIndexSettings : IDynamicIndexSettings
{
/// <summary>
/// The number of primary shards that an index should have. Defaults to 5.
/// This setting can only be set at index creation time. It cannot be changed on a closed index.
/// The number of primary shards that an index should have. Defaults to 5.
/// This setting can only be set at index creation time. It cannot be changed on a closed index.
/// </summary>
int? NumberOfShards { get; set; }

Expand All @@ -17,24 +18,27 @@ public interface IIndexSettings : IDynamicIndexSettings
/// <para>EXPERT MODE toggle</para>
/// </summary>
FileSystemStorageImplementation? FileSystemStorageImplementation { get; set; }

/// <summary>
/// Settings associated with queries.
/// </summary>
IQueriesSettings Queries { get; set; }
}

/// <inheritdoc />
public class IndexSettings: DynamicIndexSettings, IIndexSettings
{
public IndexSettings() : base() { }
public IndexSettings() { }
public IndexSettings(IDictionary<string, object> container) : base(container) { }
public IndexSettings(Dictionary<string, object> container)
: base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value))
{ }

/// <inheritdoc />
public int? NumberOfShards { get; set; }

/// <inheritdoc />
public FileSystemStorageImplementation? FileSystemStorageImplementation { get; set; }

//public void Add(string setting, object value) => _backingDictionary.Add(setting, value);
/// <inheritdoc />
public IQueriesSettings Queries { get; set; }
}

/// <inheritdoc />
Expand All @@ -50,6 +54,8 @@ public class IndexSettingsDescriptor: DynamicIndexSettingsDescriptorBase<IndexSe
public IndexSettingsDescriptor FileSystemStorageImplementation(FileSystemStorageImplementation? fs) =>
Assign(a => a.FileSystemStorageImplementation = fs);

public IndexSettingsDescriptor Queries(Func<QueriesSettingsDescriptor, IQueriesSettings> selector) =>
Assign(a => a.Queries = selector?.Invoke(new QueriesSettingsDescriptor()));
}

}
Expand Up @@ -74,11 +74,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
d[UpdatableIndexSettings.SlowlogIndexingLevel] = indexing?.LogLevel;
d[UpdatableIndexSettings.SlowlogIndexingSource] = indexing?.Source;


var indexSettings = value as IIndexSettings;
d["index.number_of_shards"] = indexSettings?.NumberOfShards;
d[UpdatableIndexSettings.NumberOfReplicas] = indexSettings?.NumberOfReplicas;
d[UpdatableIndexSettings.StoreType] = indexSettings?.FileSystemStorageImplementation;
d["index.queries.cache.enabled"] = indexSettings?.Queries?.Cache?.Enabled;

d[UpdatableIndexSettings.Analysis] = ds.Analysis;

Expand All @@ -92,7 +92,7 @@ public JObject Flatten(JObject original, string prefix = "", JObject newObject =
foreach (var property in original.Properties())
{
if (property.Value is JObject && property.Name != UpdatableIndexSettings.Analysis)
Flatten(property.Value.Value<JObject>(), property.Name + ".", newObject);
Flatten(property.Value.Value<JObject>(), prefix + property.Name + ".", newObject);
else newObject.Add(prefix + property.Name, property.Value);
}
return newObject;
Expand Down Expand Up @@ -184,6 +184,10 @@ private void SetKnownIndexSettings(JsonReader reader, JsonSerializer serializer,
Set<FileSystemStorageImplementation?>(s, settings, UpdatableIndexSettings.StoreType, v => s.FileSystemStorageImplementation = v,
serializer);

var queries = s.Queries = new QueriesSettings();
var queriesCache = s.Queries.Cache = new QueriesCacheSettings();
Set<bool?>(s, settings, "index.queries.cache.enabled", v => queriesCache.Enabled = v);

IDictionary dict = s;
foreach (var kv in settings)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Nest/Nest.csproj
Expand Up @@ -605,6 +605,8 @@
<Compile Include="IndexModules\IndexSettings\Merge\MergePolicySettings.cs" />
<Compile Include="IndexModules\IndexSettings\Merge\MergeSchedulerSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Merge\MergeSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Queries\IQueriesCacheSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Queries\IQueriesSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Settings\DynamicIndexSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Settings\IndexSettings.cs" />
<Compile Include="IndexModules\IndexSettings\Settings\IndexSettingsConverter.cs" />
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
{"index.unassigned.node_left.delayed_timeout", "1m" },
{"index.number_of_shards", 1},
{"index.store.type", "mmapfs"},
{"index.queries.cache.enabled", true},
};

/**
Expand All @@ -55,7 +56,8 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
.TotalShardsPerNode(10)
.UnassignedNodeLeftDelayedTimeout(TimeSpan.FromMinutes(1))
.RefreshInterval(-1)
.FileSystemStorageImplementation(FileSystemStorageImplementation.MMap);
.FileSystemStorageImplementation(FileSystemStorageImplementation.MMap)
.Queries(q => q.Cache(c => c.Enabled()));

/**
*/
Expand All @@ -81,7 +83,8 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
RoutingAllocationTotalShardsPerNode = 10,
UnassignedNodeLeftDelayedTimeout = "1m",
RefreshInterval = -1,
FileSystemStorageImplementation = FileSystemStorageImplementation.MMap
FileSystemStorageImplementation = FileSystemStorageImplementation.MMap,
Queries = new QueriesSettings { Cache = new QueriesCacheSettings { Enabled = true } }
};
}
}
Expand Down
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.Integration;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class CreateIndexApiTests : ApiIntegrationTestBase<ICreateIndexResponse,
{
{ "index.number_of_replicas", 1 },
{ "index.number_of_shards", 1 },
{ "index.queries.cache.enabled", true },
}
};

Expand All @@ -39,15 +41,43 @@ public class CreateIndexApiTests : ApiIntegrationTestBase<ICreateIndexResponse,
.Settings(s => s
.NumberOfReplicas(1)
.NumberOfShards(1)
.Queries(q => q
.Cache(c => c
.Enabled()
)
)
);

protected override CreateIndexRequest Initializer => new CreateIndexRequest(CallIsolatedValue)
{
Settings = new Nest.IndexSettings()
Settings = new Nest.IndexSettings
{
NumberOfReplicas = 1,
NumberOfShards = 1,
Queries = new QueriesSettings
{
Cache = new QueriesCacheSettings
{
Enabled = true
}
}
}
};

protected override void ExpectResponse(ICreateIndexResponse response)
{
response.IsValid.Should().BeTrue();

var indexSettings = this.Client.GetIndexSettings(g => g.Index(CallIsolatedValue));

indexSettings.IsValid.Should().BeTrue();
indexSettings.Indices.Should().NotBeEmpty().And.ContainKey(CallIsolatedValue);

var settings = indexSettings.Indices[CallIsolatedValue];

settings.Settings.NumberOfShards.Should().Be(1);
settings.Settings.NumberOfReplicas.Should().Be(1);
settings.Settings.Queries.Cache.Enabled.Should().Be(true);
}
}
}

0 comments on commit 29e0e6e

Please sign in to comment.