Requring object field names to be lowercase to search


(Duy) #1

I'm experimenting with indexing my search results. It seems like I have to have my object field names to be lower case (not the data) when I create an index and populate my index to be able to do a Search via Match. If I have my object field name to be camel case, I'm unable to Search. I would like to keep my object field name camel case and be able to search my data?


(Mark Walkom) #2

Why not?


(Duy) #3

Here's an example: Why does my ElasticInstrument object field names have to be in lower case for my search to work?

void Main()
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200")).DefaultIndex("instruments").RequestTimeout(TimeSpan.FromMinutes(2));
var client = new ElasticClient(settings);

var indexName = "instruments";
client.DeleteIndex(indexName);

SearchIndexManager.CreateIndex(indexName);
var instruments =
	(from i in Instruments
	 join ibd in InstrumentsByDays on new { EffectiveDate = DateTime.Parse("2017-08-18"), Id = i.Id } equals new { EffectiveDate = ibd.EffectiveDate, Id = ibd.InstrumentId }
	 join it in InstrumentTypes on i.InstrumentTypeId equals it.Id
	 where ibd.TradedCountry == "US"
	 select new ElasticInstrument() { id = i.Id, ticker = ibd.Ticker, sedol1 = ibd.SEDOL1, sedol2 = ibd.SEDOL2, cusip = ibd.CUSIP, isin = ibd.ISIN, figi = i.FIGI, bloombergUniqueId = ibd.BloombergUniqueId, bloombergTicker = ibd.BloombergTicker, country = ibd.TradedCountry, currency = ibd.Currency, primaryExchangeCode = ibd.PrimaryExchangeCode, exchangeCode = ibd.ExchangeCode, instrumentType = it.Name, bloombergSecurityType = i.BloombergSecurityType, bloombergSecurityType2 = i.BloombergSecurityType2 }).Take(100).ToList();
var results = SearchIndexManager.BuildIndexBulk(instruments, 10, indexName, "elasticinstrument");

	var result = SearchClient.SearchByTerm("BBG000BPH459");
	result.Dump();

}

public static class SearchClient
{
public static List SearchByTicker(string searchValue)
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200")).DefaultIndex("instruments").RequestTimeout(TimeSpan.FromMinutes(2));
var client = new ElasticClient(settings);
var response = client.Search(s => s.Query(q =>q.Match(m => m.Field(f => f.ticker).Query(searchValue)))).Documents.ToList();
return response;
}
}

public static class SearchIndexManager
{
public static void CreateIndex(string name)
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200")).DefaultIndex("instruments").RequestTimeout(TimeSpan.FromMinutes(2));
var client = new ElasticClient(settings);
client.CreateIndex(name, c => c
.Mappings(m => m.Map(mp => mp.AutoMap())));
}

public static List<ElasticsearchResponse<Stream>> BuildIndexBulk(List<ElasticInstrument> instruments, int batchSize, string index, string indexType)
{

	var bulkInstrumentsForIndexing = new List<object>();
	var responses = new List<ElasticsearchResponse<Stream>>();
	int totalRecords = instruments.Count();

	var settings = new ConnectionConfiguration(new Uri("http://localhost:9200")).RequestTimeout(TimeSpan.FromMinutes(10));
	var client = new ElasticLowLevelClient(settings);

	for (int i = 0; i < totalRecords; i = i + batchSize)
	{
		var items = instruments.Skip(i).Take(batchSize);
		foreach (var e in items)
		{
			var objIndex = new { index = new { _index = index, _type = indexType, _id = e.id } };
			bulkInstrumentsForIndexing.Add(objIndex);
			bulkInstrumentsForIndexing.Add(e);
		}

		var indexResponse = client.Bulk<Stream>(bulkInstrumentsForIndexing);
		responses.Add(indexResponse);
		bulkInstrumentsForIndexing.Clear(); //clear for next batch
	}

	return responses;
}

}

public class ElasticInstrument
{
// Why do field names need to be in lower case for search to work?
public int id { get; set; }
public string ticker { get; set; }
public string sedol1 { get; set; }
public string sedol2 { get; set; }
public string cusip { get; set; }
public string isin { get; set; }
public string figi { get; set; }
public string bloombergUniqueId { get; set; }
public string bloombergTicker { get; set; }
public string country { get; set; }
public string currency { get; set; }
public string exchangeCode { get; set; }
public string primaryExchangeCode { get; set; }
public string instrumentType { get; set; }
public string bloombergSecurityType { get; set; }
public string bloombergSecurityType2 { get; set; }
}


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.