In our project, a program does not insert all fields when creating a document, and other programs will report errors when reading the document. I want to set elasticsearch to insert all fields when creating a document. How should I set it, or do you have other solutions
Welcome to our community!
What do you want Elasticsearch to insert into these fields? Because what is likely happening is that the document will have the field, but a null value, which your app might not like.
For example, the index in the picture has five fields. When I want to create a document, I must force to fill in the values of five fields instead of three or two fields. Can I realize it
Please don't post pictures of text or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them
Have you seen null_value | Elasticsearch Guide [7.13] | Elastic?
You can use an Ingest Pipeline and test if the values exist and if they don't set your default value(s)
I'm really sorry. I don't know the community rules. I republished the code. Is that ok?
Let me describe my problem again. Please help me look at it. For example, the code I published created a test index, which contains five fields
PUT test
{
"settings": {
"index": {
"max_result_window": "100000000"
}
},
"mappings": {
"warnone": {
"dynamic": "strict",
"properties": {
"sex": {
"index": "not_analyzed",
"type": "string"
},
"phone": {
"index": "not_analyzed",
"type": "string"
},
"email": {
"index": "not_analyzed",
"type": "string"
},
"name": {
"index": "not_analyzed",
"type": "string"
},
"age": {
"index": "not_analyzed",
"type": "string"
}
}
}
}
}
Now I create a three field document for the test index, which is feasible, but I don't want to allow this way to create documents
POST test/warnone
{
"name": "Tom",
"age": "eighteen",
"sex": "man"
}
I want to include all the fields of the index when creating the document, otherwise the document cannot be created successfully
POST test/warnone
{
"name": "Tom",
"age": "eighteen",
"sex": "man",
"email": "123456@gmail.com",
"phone": "1234567890"
}
I want to force the document to include all fields of the index when creating the document. How do I set it? In addition, my elastic search is version 2.4.0. For personal reasons, version 7.13 cannot be updated at present.
Thank you for your reply, but my version is 2.4.0. Is there any feasible solution
Then you need to check it in your client application, unless you upgrade to a version supporting ingest pipelines.
2.4 has been EOL for a long, long time. Please upgrade.
So if I want to realize my idea, I have to upgrade, right
2.4 has null_value | Elasticsearch Guide [2.4] | Elastic, otherwise you need to handle it all in your own code.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.