is RestKit has default mapping if omit some field - restkit

my json and object both contain some fields with same name, and my mapping like this:
[mapping addAttributeMappingsFromArray :#[ #"postId", #"fieldname1", #"fieldname2", #"fieldname3", #"fieldname4", #"fieldname5"]];
if json was returned without fieldname4, it is fine, the mapping just ignore it.
but on the contrary, if I forget some field in mapping, for example.
[mapping addAttributeMappingsFromArray :#[ #"postId"]];
then the object will got nothing except postId even if json contains every field.
is there someway I can tell the mapping to do some "default mapping" if json and object contained same field name. So I need not list all the field names to the mapping even if their field names are all same.

No. You explicitly list the keys which should be processed.
You could create a dynamic mapping which introspects on the response and the destination object and creates a mapping including all keys. RestKit doesn't do that because it's slow...

Related

Google Drive API Listing Files with Field Paramter Not Working

I am currently listing some files with the Google Drive API. However, the default list only lists id, name, and mimeType. I know that the fields parameter can list more than just the default, but when I put parents as a field in the Google API Playground, I get the error of Invalid field selection parents. However, when I use * in the fields parameter, it returns all the fields. Am I doing anything wrong by putting parents in the fields parameter? If so, does anyone have any idea how to include the parents field as a field in the list results?
Here is my current endpoint, which causes the error:
https://www.googleapis.com/drive/v3/files?fields=parents&key=[YOUR_API_KEY]
Thanks!
From https://www.googleapis.com/drive/v3/files?fields=parents&key=[YOUR_API_KEY], in your situation, when parents is directly put to fields as follows,
such error of Invalid field selection parents occurs. Because the method of "Files: list" returns the file list which is an array including each file metadata. Ref I think that this is the reason of your issue.
Solution:
So in this case, please set files(parents) instead of parents.
Note:
In the case of files(parents), only parents is returned. When you want to retrieve id, name, mimeType and parents, please use files(id,name,mimeType,parents) to fields.
References:
Try this API of "Files: list"
Files

problem with dynamic field elastic search

i am running Packet-beat in my server.
i'm disabled dynamic field in index mapping . it mean if new data coming . don't create new fields.
in my mapping there is not extra field but when i send a request from postman for show records . there is a new field in my result but i'm sure its not in my mapping.
how is possible?
I'm founding the answer.
in elasticsearch when set dynamic:false its mean:
The dynamic setting controls whether new fields can be added dynamically or not. It accepts three settings:
true : Newly detected fields are added to the mapping. (default)
false : Newly detected fields are ignored. These fields will not be indexed so will not be searchable but will still appear in the _source field of returned hits. These fields will not be added to the mapping, new fields must be added explicitly.
strict : If new fields are detected, an exception is thrown and the document is rejected. New fields must be explicitly added to the mapping.
extra description in this link

Conditionally retrieve fields from elasticsearch _source based on value of another field

I have a type with a field indicating if to reveal another field. For example, for a document, if ifRevealAge is true, value of the age field should be retrieved from _source and included in query result for the document. If ifRevealAge is false, then age field should not be included in the query result for the document. Is it possible by query API?
If it is not, how to do it through java API? I think the method toXContent(XContentBuilder builder, ToXContent.Params params) of GetResponse is supposed to do so but I can't find any documentation or references for how to use the method for filtering / modifying response result conditionally. The api documentation is just too concise.
Many thanks

Elasticsearch get field mapping for all fields without using asterisk (*)

To get mapping for all fields in an index, I do this:
GET http://localhost:9200/some_awesome_index/_mapping/field/*
But I don't want to use the *. Is there another way to get the same result without using a * ? I have dynamic fields, so I can't use a comma-separated list of every single field I need (without having to use the *).
If you want to the get the mapping for all the fields of all the types in an index, use
GET /index name/_mapping
If you want to get the mapping for all the fields of a single type in an index, use
GET/index name/type name/_mapping

Stored field in elastic search

In the documentation, some types, such as numbers and dates, it specifies that store defaults to no. But that the field can still be retrieved from the json.
Its confusing. Does this mean _source?
Is there a way to not store a field at all, and just have it indexed and searchable?
None of the field types are stored by default. Only the _source field is. That means you can always get back what you sent to the search engine. Even if you ask for specific fields, elasticsearch is going to parse the _source field for you and give you back those fields.
You can disable the _source if you want but then you could only retrieve the fields that you explicitly stored, according to your mapping.

Resources