JSON single property formatting - c#

I have following JSON:
{
"cap": [
{
"type": "test"
},
{
"type": "test1"
},
{
"type": "test2",
"bla": "tst"
}
]
}
I want every object that have single property to be one line formated
{ "type": "test" }
so the final JSON should be
{
"cap": [
{ "type": "test" },
{ "type": "test1" },
{
"type": "test2",
"bla": "tst"
}
]
}
How to do this in c#?

Related

NjsonSchema Validation If Property1 is equal to Something then require Property2

I seem to not be able to get const or enum working as part of an if-then-else JSON schema validation.
They seem to be interchangeable when 1 validation value is concerned. (Reference)
Here is my JSON schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Test_Schema",
"description": "A schema for validating a test object",
"type": "object",
"additionalProperties": false,
"properties": {
"GeneralData": {
"type": "object",
"description": "Advsor and admin customer information",
"properties": {
"Name": {
"type": [ "string", "null" ],
"description": "Customer's advisor name"
},
"Age": {
"type": [ "string", "null" ],
"description": "Customer's advisor email"
},
"Location": {
"type": [ "string", "null" ],
"description": "The advisor's manager email'"
}
},
"required": [ "Name", "Location", "Age" ]
},
"ClientData": {
"type": "object",
"description": "Customer's information",
"additionalProperties": false,
"properties": {
"Title": {
"type": [ "string", "null" ]
},
"Forename": {
"type": [ "string", "null" ]
},
"Surname": {
"type": [ "string" ]
}
},
"required": [ "Title" ],
"if": {
"properties": {
"Forename": { "enum": [ "Soameonea" ] }
},
"required": [ "Forename" ]
},
"then": { "required": [ "Surname" ] },
"else": false
}
}
}
If Forename = "Someone" I want Surname to be required.
Here is my jsonObject after serialization:
{
"GeneralData": {
"Name": "Not Relevant",
"Age": "Not Relevant",
"Location": "Not Relevant"
},
"ClientData": {
"Title": "SomeTitle",
"Forename": "Someone",
"Surname": null
}
}
Validation code:
internal void ValidateDataObjectOnSchema()
{
var dataObject = PopulateDataObject();
var json = JsonConvert.SerializeObject(dataObject);
var result = GetSchema().Validate(json);
var errors = result.Select(x =>
{
return new Errors() { Title = x.Property, Description = x.Schema.Description };
});
var i = errors;
}
internal JsonSchema GetSchema()
{
return JsonSchema.FromFileAsync("Test/testSchema.json").Result;
}
Right now it still requires Surname, even though the enum Soameonea != Someone and I only require Title. <== Issue1
In the JSON schema if I set "Surname":{"type":["string","null]} then the error disappears and still I don't get the error if I then change the if condition for the Forename enum to "Someone". <== Issue 2
I cannot get a different validation output if I replace Enum with Const, So if I can get one to work I'm sure the other will follow.
I've found several answers to this question (Answer 1), I try to implement the same thing and for some reason, it fails in my case.
What am I missing?
In the JSON schema if I set "Surname":{"type":["string","null]} then the error disappears
A property with a null value still has a value. If you want to say that the property value must not only exist, but not be null, then add "type": "string" to your then condition.
Update:
As #Relequestial mentioned in one of the comments it seems NJson Schema only supports up to Draft 04, this is why if-then-else did not work and implication should be used instead. Below is my solution with an alternative package.
The same code and json work with the package Newtonsoft.Json.Schema (Reference)
Code:
internal void ValidateDataObjectOnSchemaWithNewtonSoftJson()
{
var dataObject = PopulateDataObject();
var settings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore
};
var jsonDataObjectString = JsonConvert.SerializeObject(dataObject, settings);
JObject jsonDataObject = JObject.Parse(jsonDataObjectString);
var jsonSchemaFile = File.ReadAllText("Test/testSchema.json");
var schema = JSchema.Parse(jsonSchemaFile);
;
IList<ValidationError> messages;
var result = jsonDataObject.IsValid(schema, out messages);
var errors = GetReadableResult(result, messages);
}
private List<Errors> GetReadableResult(bool result, IList<ValidationError> messages)
{
var errors = new List<Errors>();
if (!result)
{
foreach (var error in messages)
{
if (error.ChildErrors.Count > 0)
{
errors.Add(
new Errors()
{
Path = error.ChildErrors.FirstOrDefault()?.Path,
Kind = error.ChildErrors.FirstOrDefault()?.Message
});
}
else
{
errors.Add(new Errors()
{
Path = error.Path,
Kind = error.Message
});
}
}
}
return errors;
}
JsonSchema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Test_Schema",
"description": "A schema for validating a test object",
"type": "object",
"additionalProperties": false,
"properties": {
"GeneralData": {
"type": "object",
"description": "Advsor and admin customer information",
"properties": {
"Name": {
"type": [ "string", "null" ],
"description": "Customer's advisor name"
},
"Age": {
"type": [ "string", "null" ],
"description": "Customer's advisor email"
},
"Location": {
"type": [ "string", "null" ],
"description": "The advisor's manager email'"
}
},
"required": [ "Name", "Location", "Age" ]
},
"ClientData": {
"type": "object",
"description": "Customer's information",
"additionalProperties": false,
"properties": {
"Title": {
"type": [ "string", "null" ]
},
"Forename": {
"type": "string"
},
"Surname": {
"type": [ "string" ]
}
},
"required": [ "Title" ],
"if": {
"properties": {
"Forename": { "enum": [ "Someone" ] }
},
"required": [ "Forename" ]
},
"then": { "required": [ "Surname" ] },
"else": {}
}
}
}
The only addition would be to make the GetReadableResult recursive for Errors which have multiple child items.

Performing an update on objects from an array by using object own values

Having a collection sampled by next:
{
"_id": {
"$oid": "6139b08ee5a3119445892f94"
},
"type": "bike",
"specs": [
{
"name": "giant",
"models": [
{
"name": "v1",
"categories": [
{
"name": "v11",
"price": 0
},
{
"name": "v12",
"price": 0.1
},
{
"name": "v13",
"price": 0.1
}
]
},
{
"name": "v2",
"categories": [
{
"name": "v21",
"price": 1
},
{
"name": "v22",
"price": 0.1
}
]
}
]
},
{
"name": "sputnik",
"models": [
{
"name": "s1",
"categories": [
{
"name": "s11",
"price": 20
},
{
"name": "s12",
"price": 0.9
},
{
"name": "s13",
"price": 1.1
}
]
},
{
"name": "s2",
"categories": [
{
"name": "s31",
"price": 1
},
{
"name": "s32",
"price": 0.1
}
]
}
]
}
]
}
In order to edit models items by adding a new subdocument with next structure:
"valid": {
"isValid": true,
"currentName": [value from name field]
}
and remove field name
Almost achieved that by using Aggregations:
var dineInOptionsDefinition =
BsonDocument.Parse("{ isValid: 5, currentName: '$specs.name'}");
var addNewFieldsDefinition = new BsonDocument
{
{ "$addFields", new BsonDocument
{
{
"specs.models.valid", dineInOptionsDefinition
}
}
}
};
var t1 = collection
.Aggregate()
.Match(filterDefinition)
.AppendStage<BsonDocument>(addNewFieldsDefinition)
.Merge(collection);
The problem I'm facing is the value for currentName - as result it's an array of concatenated name fields values. Any clue how to get the value from the current document field value?

ElasticSearch Nest, edge n gram with Fuziness

I am using ElastiSearch.Net and NEST v7.10.0
I have these settings and mappings for elastic search.
{
"settings": {
"index": {
"analysis": {
"filter": {},
"analyzer": {
"keyword_analyzer": {
"filter": [
"lowercase",
"asciifolding",
"trim"
],
"char_filter": [],
"type": "custom",
"tokenizer": "keyword"
},
"edge_ngram_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "edge_ngram_tokenizer"
},
"edge_ngram_search_analyzer": {
"tokenizer": "lowercase"
}
},
"tokenizer": {
"edge_ngram_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter"
]
}
}
}
}
},
"mappings": {
"properties": {
"MatchName": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"edgengram": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "edge_ngram_search_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
},
"CompetitionName": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"edgengram": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "edge_ngram_search_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
}
}
}
}
I have indexed 3 documents with values
{
"_source": {
"CompetitionName": "Premiership",
"MatchName": "Dundee Utd - St Johnstone",
}
},
{
"_source": {
"CompetitionName": "2nd Div, Vastra Gotaland UOF",
"MatchName": "IF Limhamn Bunkeflo - FC Rosengaard 1917",
}
},
{
"_source": {
"CompetitionName": "Bundesliga",
"MatchName": "Hertha Berlin - Eintracht Frankfurt",
}
}
And i am searching with Fuziness.Auto in both fields with string "bunde".
I want to achieve to get all the documents with the search above.
But for the query below i get nothing.
string value = "bunde";
BoolQuery boolQuery = new BoolQuery
{
Should = new List<QueryContainer>
{
new QueryContainer(new FuzzyQuery
{
Field = Infer.Field<EventHistoryDoc>(path:eventHistoryDoc => eventHistoryDoc.MatchName),
Value = value,
Fuzziness = Fuzziness.Auto,
}),
new QueryContainer(new FuzzyQuery
{
Field = Infer.Field<EventHistoryDoc>(path:eventHistoryDoc => eventHistoryDoc.CompetitionName),
Value = value,
Fuzziness = Fuzziness = Fuzziness.Auto,
})
}
};
ISearchRequest searchRequest = new SearchRequest
{
Query = new QueryContainer(boolQuery),
};
var json = _elasticClient.RequestResponseSerializer.SerializeToString(searchRequest);
ISearchResponse<EventHistoryDoc> searchResponse = await _elasticClient.SearchAsync<EventHistoryDoc>(searchRequest);
If i search with string "bundes" i get only one document
{
"_source": {
"CompetitionName": "Bundesliga",
"MatchName": "Hertha Berlin - Eintracht Frankfurt",
}
}
Any idea about changes should i do to settings, mapping or query in order to get as response all the documents above?
I am not aware of the syntax of Elasticsearch Nest, but in JSON format you can achieve your result in the following way:
Adding a working example with index mapping, search query, and search result
(For now, I have removed the keyword_analyzer and edge_ngram_search_analyzer from the index mapping, as you just wanted to return all the documents with edge ngram along with fuzziness)
Index Mapping:
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit"
]
}
}
},
"max_ngram_diff": 50
},
"mappings": {
"properties": {
"CompetitionName": {
"type": "text",
"analyzer": "my_analyzer"
},
"MatchName": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
Search Query:
{
"query": {
"multi_match": {
"query": "bunde",
"fuzziness": "AUTO"
}
}
}
Search Result:
"hits": [
{
"_index": "64968421",
"_type": "_doc",
"_id": "1",
"_score": 2.483365,
"_source": {
"CompetitionName": "Premiership",
"MatchName": "Dundee Utd - St Johnstone"
}
},
{
"_index": "64968421",
"_type": "_doc",
"_id": "3",
"_score": 2.4444416,
"_source": {
"CompetitionName": "Bundesliga",
"MatchName": "Hertha Berlin - Eintracht Frankfurt"
}
},
{
"_index": "64968421",
"_type": "_doc",
"_id": "2",
"_score": 0.6104546,
"_source": {
"CompetitionName": "2nd Div, Vastra Gotaland UOF",
"MatchName": "IF Limhamn Bunkeflo - FC Rosengaard 1917"
}
}
]
The index mapping provided in the question is also correct. When using the same index mapping (as provided in the question) and searching for bunde in the multi-match query (as shown above), all the three documents are returned (which is the expected result).

Deserialize Complex Json in C# using Json.net

I have some complex JSon that I am trying to parse into something meaningful. I'm attempting to deserialize using C# Json.net but I can't get the values that I need. What I need is the value from every ColData node except those in a "summary" section. I am able to deserialize into an object using but I am stuck there.
string pandltext = #"{
"Header": {
"Time": "2017-08-24T08:32:58-07:00",
"ReportName": "ProfitAndLoss",
"ReportBasis": "Accrual",
"StartPeriod": "2017-06-01",
"EndPeriod": "2017-06-30",
"SummarizeColumnsBy": "Total",
"Currency": "USD",
"Option": [
{
"Name": "AccountingStandard",
"Value": "GAAP"
},
{
"Name": "NoReportData",
"Value": "false"
}
]
},
"Columns": {
"Column": [
{
"ColTitle": "",
"ColType": "Account",
"MetaData": [
{
"Name": "ColKey",
"Value": "account"
}
]
},
{
"ColTitle": "Total",
"ColType": "Money",
"MetaData": [
{
"Name": "ColKey",
"Value": "total"
}
]
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Income"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Design income",
"id": "82"
},
{
"value": "975.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Discounts given",
"id": "86"
},
{
"value": "-30.50"
}
],
"type": "Data"
},
{
"Header": {
"ColData": [
{
"value": "Landscaping Services",
"id": "45"
},
{
"value": "360.00"
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Job Materials",
"id": "46"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Fountains and Garden Lighting",
"id": "48"
},
{
"value": "550.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Plants and Soil",
"id": "49"
},
{
"value": "1820.72"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Sprinklers and Drip Systems",
"id": "50"
},
{
"value": "30.00"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Job Materials"
},
{
"value": "2400.72"
}
]
},
"type": "Section"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Landscaping Services"
},
{
"value": "2760.72"
}
]
},
"type": "Section"
},
{
"ColData": [
{
"value": "Pest Control Services",
"id": "54"
},
{
"value": "-100.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Sales of Product Income",
"id": "79"
},
{
"value": "44.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Services",
"id": "1"
},
{
"value": "400.00"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Income"
},
{
"value": "4049.22"
}
]
},
"type": "Section",
"group": "Income"
},
{
"Summary": {
"ColData": [
{
"value": "Gross Profit"
},
{
"value": "4049.22"
}
]
},
"type": "Section",
"group": "GrossProfit"
},
{
"Header": {
"ColData": [
{
"value": "Expenses"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Automobile",
"id": "55"
},
{
"value": "19.99"
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Fuel",
"id": "56"
},
{
"value": "179.15"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Automobile"
},
{
"value": "199.14"
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Job Expenses",
"id": "58"
},
{
"value": "108.09"
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Job Materials",
"id": "63"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Decks and Patios",
"id": "64"
},
{
"value": "88.09"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Job Materials"
},
{
"value": "88.09"
}
]
},
"type": "Section"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Job Expenses"
},
{
"value": "196.18"
}
]
},
"type": "Section"
},
{
"Header": {
"ColData": [
{
"value": "Legal & Professional Fees",
"id": "12"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Accounting",
"id": "69"
},
{
"value": "75.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Lawyer",
"id": "71"
},
{
"value": "100.00"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Legal & Professional Fees"
},
{
"value": "175.00"
}
]
},
"type": "Section"
},
{
"ColData": [
{
"value": "Maintenance and Repair",
"id": "72"
},
{
"value": "185.00"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Meals and Entertainment",
"id": "13"
},
{
"value": "5.66"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Rent or Lease",
"id": "17"
},
{
"value": "900.00"
}
],
"type": "Data"
},
{
"Header": {
"ColData": [
{
"value": "Utilities",
"id": "24"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Gas and Electric",
"id": "76"
},
{
"value": "114.09"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Telephone",
"id": "77"
},
{
"value": "74.36"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Utilities"
},
{
"value": "188.45"
}
]
},
"type": "Section"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Expenses"
},
{
"value": "1849.43"
}
]
},
"type": "Section",
"group": "Expenses"
},
{
"Summary": {
"ColData": [
{
"value": "Net Operating Income"
},
{
"value": "2199.79"
}
]
},
"type": "Section",
"group": "NetOperatingIncome"
},
{
"Header": {
"ColData": [
{
"value": "Other Expenses"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"value": "Miscellaneous",
"id": "14"
},
{
"value": "916.00"
}
],
"type": "Data"
}
]
},
"Summary": {
"ColData": [
{
"value": "Total Other Expenses"
},
{
"value": "916.00"
}
]
},
"type": "Section",
"group": "OtherExpenses"
},
{
"Summary": {
"ColData": [
{
"value": "Net Other Income"
},
{
"value": "-916.00"
}
]
},
"type": "Section",
"group": "NetOtherIncome"
},
{
"Summary": {
"ColData": [
{
"value": "Net Income"
},
{
"value": "1283.79"
}
]
},
"type": "Section",
"group": "NetIncome"
}
]
}
}
// Deserialize to object
var rootObj = JsonConvert.DeserializeObject<ProfitLoss.Rootobject>( pandltext );
I've tried querying a JContainer like is mentioned in this post. I've tried deserlializing a fragment like is mentioned in the documentation and I've tried using linq as mentioned here in the documentation. So far all of my efforts have met varying degrees of "success" but none have yielded the values I'm trying to get. Eventually this data will be bound to a WPF DataGrid for viewing.
Edit:
Added entire Json file
These are a couple attempts to get something, but I run into null values in both cases.
// This always returns null
var results2 = doc.Descendants()
.OfType<JObject>()
.Where( x => x[ "value" ] != null );
// This gives me a null exception error
var doc1 = ( JContainer ) o[ "Rows" ];
foreach ( var row in rootObj.Rows.Row )
{
// Get a null exception
foreach ( var row2 in row.Rows.Row )
{
Console.WriteLine( row2.ToString() );
}
}
Edit 2:
Using what #Eser gave as a starting point, I am able to get a list of values, but unfortunately it's just a list of values. Instead of getting something like
"Design income", "975.00"
"Discounts given", "-30.50"
I get
"Design income"
"975"
"Discounts given"
"-30.50"
Here is the code I'm using to get a list of values:
var jObj = JObject.Parse( pandltext );
var results = jObj.SelectTokens( "$..Rows.Row[?(#.type == 'Data')]..value" ).ToList();
var jObj = JObject.Parse(json);
var colData = jObj.SelectTokens("$..ColData")
.Except(jObj.SelectTokens("$..Summary.ColData"))
.ToList();
EDIT
foreach(var item in colData)
{
Console.WriteLine(string.Join("=", item.Select(x => x["value"])));
}
or
var finalList = colData.Select(item => item.Select(x => (string)x["value"]).ToList())
.ToList();
    public class Option
    {
         public string Name { get; set; }
    public string Value { get; set; }
   }
    public class Header
    {
        public DateTime Time { get; set; }
        public string ReportName { get; set; }
        public string ReportBasis { get; set; }
        public string StartPeriod { get; set; }
        public string EndPeriod { get; set; }
        public string SummarizeColumnsBy { get; set; }
        public string Currency { get; set; }
        public IList<Option> Option { get; set; }
    }
    public class MetaData
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }
    public class Column
    {
        public string ColTitle { get; set; }
        public string ColType { get; set; }
        public IList<MetaData> MetaData { get; set; }
    }
    public class Columns
    {
        public IList<Column> Column { get; set; }
    }
    public class ColData
    {
        public string value { get; set; }
        public string id { get; set; }
    }
    public class ColData
    {
        public string value { get; set; }
        public string id { get; set; }
    }
    public class Row
   {
      public IList<ColData> ColData { get; set; }
        public string type { get; set; }
    }
    public class Rows
    {
        public IList<Row> Row { get; set; }
    }
    public class ColData
    {
        public string value { get; set; }
    }
    public class Summary
    {
        public IList<ColData> ColData { get; set; }
    }
    public class ColData
    {
        public string value { get; set; }
        public string id { get; set; }
    }
    public class Row
    {
        public  Header { get; set; }
        public Rows Rows { get; set; }
        public Summary Summary { get; set; }
        public string type { get; set; }
        public IList<ColData> ColData { get; set; }
    }
    public class Rows
    {
        public IList<Row> Row { get; set; }
    }
    public class Row
    {
        public IList<ColData> ColData { get; set; }
        public string type { get; set; }
        public  Header { get; set; }
        public Rows Rows { get; set; }
        public  Summary { get; set; }
    }
    public class Rows
    {
        public IList<Row> Row { get; set; }
    }
    public class Row
    {
        public  Header { get; set; }
        public Rows Rows { get; set; }
        public  Summary { get; set; }
        public string type { get; set; }
        public string group { get; set; }
    }
    public class Rows
    {
        public IList<Row> Row { get; set; }
    }
    public class Example
    {
        public Header Header { get; set; }
        public Columns Columns { get; set; }
        public Rows Rows { get; set; }
    }
and use it with :
Example results = Newtonsoft.JSON.JsonConvert.DeserializeObject<Example>(json);

Elasticsearch NEST 5.x Koelnerphonetic not matching

UPDATE
I changed the approach of the question
I'm trying to apply phonetic search with koelner phonetics and also ngram is used.
Index configuration I'm using:
{
"testnew": {
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "testnew",
"creation_date": "1489672932033",
"analysis": {
"filter": {
"koelnerPhonetik": {
"replace": "false",
"type": "phonetic",
"encoder": "koelnerphonetik"
}
},
"analyzer": {
"koelnerPhonetik": {
"type": "custom",
"tokenizer": "koelnerPhonetik"
},
"ngram_analyzer": {
"type": "custom",
"tokenizer": "ngram_tokenizer"
}
},
"tokenizer": {
"koelnerPhonetik": {
"type": "standard"
},
"ngram_tokenizer": {
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
],
"min_gram": "2",
"type": "ngram",
"max_gram": "20"
}
}
},
...
}
}
}
}
}
Ive got one document that looks like this:
{
"_index": "testnew",
"_type": "person",
"_id": "3",
"_score": 1,
"_source": {
"name": "Can",
"fields": {
"phonetic": {
"type": "string",
"analyzer": "koelnerPhonetik"
}
}
}
It is mapped like this:
GET testnew/person/_mapping
"name": {
"type": "text",
"analyzer": "koelnerPhonetik"
}
Why cant I find 'Can' by searching for 'Kan' in this query?
GET testnew/person/_search
{
"query": {
"match": {
"name.phonetic": {
"query": "Kan"
}
}
}
}

Categories