0

we have a system in which a client can add new fields to his index mapping in an xml file. When that happens we would take the xml file and based on it create index in the search engine. This is a legacy requirement which we need to support.

So if user uploads xml file

<Group name="some group">
    <Member field="description" type="text"/>
    <Member field="name" type="Date"/>
</Group>

I need to be able to call ElastiSearch to create such an index mapping.

PUT /my-index-000001
{
  "mappings": {
    "properties": {
      "description": { "type": "integer" },  
      "name":        { "type": "date"  }    
    }
  }
}

Now the problem is I'm not sure how to do it in .NET client since it's strongly typed.

I would need to create a class and call Create method to do it.

client.Indices.Create("my-index-000001", c => c
                .Map<SomeClass>(m => m
                    .AutoMap<SomeClass>()
                )

Now this is something I can't do since I don't know what kind of properties will exist in the xml file.

Is there some other way to do it ? Maybe with some kind of a builder for Index class ?

1 Answer 1

1

I would just convert XML to Dictionary<PropertyName, IProperty> and use it in client.Indices.PutMappingAsync method to update index definition, something like

var request = new PutMappingRequest("test")
{
    Properties = new Properties(new Dictionary<PropertyName, IProperty>
    {
        { "field1", new TextProperty { Name = fieldName, Analyzer = "standard" } }
    })
};
await client.Indices.PutMappingAsync(request);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.