How should I design index in ElasticSearch for schema less documents with user defined fields - elasticsearch

Currently we use Mysql as database for our multi-tenant web application, in order to improve our search we decided to move to ElasticSearch. We have an Entity in Mysql with some base fields and every tenant can define his own custom fields(can be of any data type) for that entity. What are the best practices for designing index in elastic search for above problems?
Will dynamic mapping work fine in the above case.

Elasticsearch is great tool to define custom fields, you simply can index data without define nothing.
In some cases you have to define fields mapping, for example in date field or Geo point field, if you don't mapping this field, elastic will not treat this field as you wish.
So if your custom fields is not date or Geo point you can allow tenant define custom fields.

Related

Is there any way to implement multiple reference in servicenow?

In service now for reference, there's a field type called 'reference'. Now I need to create a multi-reference field. But I don't see any field type for it. Can we achieve the same using field type 'List'? If yes, How to achieve it in the UI and REST API?
Multi-reference means to search through multiple objects
FYI, I'm using Madrid version and Customer Service Plugin.
No, there is no such thing as multiple table reference Field. How should the system react, if you write eg. Incidents and Catalog Items in the same Field?
I would advice you to just make two Fields, each with it's own reference table.
If you really want multiple types of references to pick, you would have to create a new table, import eg. Incident and Catalog Item references into that table and create a reference Field to that table.

Type per user in Elasticsearch?

I'm designing an analytics platform. Every user has access only to his own documents. All the documents have the same structure.
The default option is to have a userId field and use it every time I need to filter documents.
The question is will type per user improve search performance?
No, type per user won't improve your performance. It is exactly the same as filtering by the field.
But, you may consider using "filtered aliases". Since you actualy want to make different "views" for the same index you may create different aliases filtered by the userId as stated here.

Structuring complex data in Elasticsearch

I would like to allow users to upload a CSV mailing list and to insert it into elasticsearch.
Any user can define any fields they want wihtin their CSV and I would import it into elasticsearch with the exceptions of the email field which should be in all of them and a userid field which is internal and is used to filter queries for a specific user when he wants to view the mailing lists he uploaded in the past.
Initially I thought I would just create an index for each mailing list, since fields in each CSV are dynamic and can include just the email or other fields such as firstname lastname etc.. But then I read that elasticsearch doesn't really cope well with a lot of indexes.
How would you structure the index(es) to such an app? Should I create one index where I would just push data in and whatever fields that are added and create aliases for each userid?

Multiple routing field in elasticsearch

I am a newbie to elasticsearch. i need a clarification. i can understand how routing works, but I have a question.
Can i create routing for an document with multiple field. if yes, can i search the
data using single routing value. Can any on provide any example about it.
Imagine I have 5 fields: [username,id,age,dept,salary]. Now i need to create a routing value for this document. Can I do so using the username and id field?
Thanks in advance.
In answer to your question: no, you can't automatically use multiple fields for a routing value when indexing a document. You can choose one and only one field, and that field must contain a single value.
However, you could manually concatenate the username and id field and pass it in the indexing request:
PUT /index/type/id?routing=username_id
{ body }
That said, routing is a feature for more advanced users. It is very useful but does make life more complicated. You say that you're a newbie, so I'd suggest not playing with routing just yet. That can follow when you're running a 50 node cluster.

Force new _id generation in embedded MongoDB documents

I am working with ASP.NET MVC 3, C# and MongoDB. I have a model with embedded documents, but I would like to auto-generate a new _id for each of my embedded documents.
I can do this in the code and set
Model._id = ObjectId.GenerateNewId();
But I would love it if I didn't have to worry about doing this and let MongoDB auto-generate the new _id for each embedded document.
I do not want to normalize out these embedded documents into a new collection, they make sense here, but I'd like to have a unique ID for them.
The only ObjectId that MongoDB "auto-generates" is the one it uses for the primary key: _id.
When you save a document, MongoDB knows basically nothing about "schema" or "embedded" documents or "arrays of sub-documents". There's no type-checking or schema validation, so there's no way to force the instantiation of the embedded IDs.
Your best bet is to wrap it up in the parent class. If those embedded documents have a specific class tied to them, you can put the GenerateNewId() in that constructor.

Resources