Created
April 7, 2012 22:28
-
-
Save pulkitsinghal/2332494 to your computer and use it in GitHub Desktop.
RestKit ElasticSearch Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "ESBody.h" | |
| @implementation ESBody | |
| @synthesize fields, query; | |
| + (RKObjectMapping *) getObjectMapping | |
| { | |
| RKObjectMapping* objectMapping = [RKObjectMapping mappingForClass:[ESBody class]]; | |
| [objectMapping mapKeyPath:@"fields" toAttribute:@"fields"]; | |
| [objectMapping mapKeyPath:@"query" | |
| toRelationship:@"query" | |
| withMapping:[ESQuery getObjectMapping]]; | |
| return objectMapping; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "ESQuery.h" | |
| @implementation ESQuery | |
| @synthesize queryString; | |
| + (RKObjectMapping *) getObjectMapping | |
| { | |
| RKObjectMapping* objectMapping = [RKObjectMapping mappingForClass:[ESQuery class]]; | |
| [objectMapping mapKeyPath:@"query_string" | |
| toRelationship:@"queryString" | |
| withMapping:[ESQueryString getObjectMapping]]; | |
| return objectMapping; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "ESQueryString.h" | |
| @implementation ESQueryString | |
| @synthesize query, useDisMax; | |
| + (RKObjectMapping *) getObjectMapping | |
| { | |
| RKObjectMapping* objectMapping = [RKObjectMapping mappingForClass:[ESQueryString class]]; | |
| [objectMapping mapKeyPath:@"query" toAttribute:@"query"]; | |
| [objectMapping mapKeyPath:@"use_dis_max" toAttribute:@"useDisMax"]; | |
| return objectMapping; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void) runTests | |
| { | |
| ESBody *body = [[ESBody alloc] init]; | |
| body.fields = [NSArray arrayWithObjects:@"name", @"upc", nil]; | |
| body.query = [[ESQuery alloc] init]; | |
| body.query.queryString = [[ESQueryString alloc] init]; | |
| body.query.queryString.query = @"+camera +laptop"; | |
| body.query.queryString.useDisMax = [NSNumber numberWithBool:true]; | |
| // Map the root object inversely for serialization, | |
| // any nested objects will also get registered properly automagically! | |
| [ | |
| [RKObjectManager sharedManager].mappingProvider | |
| setSerializationMapping:[[ESBody getObjectMapping] inverseMapping] | |
| forClass:[ESBody class] | |
| ]; | |
| // Query should always hit the /_search url | |
| RKObjectRouter *router = [RKObjectManager sharedManager].router; | |
| [router routeClass:[ESBody class] toResourcePath:@"/_search"]; | |
| [[RKObjectManager sharedManager] postObject:body delegate:self]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2012-04-09 20:13:28.227 [59501:12803] I restkit:RKLog.m:32 RestKit initialized... | |
| 2012-04-09 20:13:28.229 [59501:12803] I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/user/Library/Application Support/iPhone Simulator/5.1/Applications/E97EDA6B-9307-473A-BF35-9447469ED64E/Library/Caches/RKClientRequestCache-XXX.XXX.XXX.XXX/SessionStore | |
| 2012-04-09 20:13:28.230 [59501:12803] I restkit.network.reachability:RKReachabilityObserver.m:117 Reachability observer initialized with IP address: XXX.XXX.XXX.XXX. | |
| 2012-04-09 20:13:28.231 [59501:12803] D restkit.network.reachability:RKReachabilityObserver.m:337 Scheduling reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=NO isMonitoringLocalWiFi=6651724 reachabilityFlags=-- -------> in main dispatch queue | |
| 2012-04-09 20:13:28.232 [59501:12803] D restkit.network:RKClient.m:271 Reachability observer changed for client <RKClient: 0x916fed0>, suspending queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> until reachability to host 'XXX.XXX.XXX.XXX' can be determined | |
| 2012-04-09 20:13:28.288 [59501:12803] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=YES isMonitoringLocalWiFi=6651724 reachabilityFlags=-R -------> | |
| 2012-04-09 20:13:28.289 [59501:12803] D restkit.network:RKClient.m:401 Reachability to host 'XXX.XXX.XXX.XXX' determined for client <RKClient: 0x916fed0>, unsuspending queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> | |
| 2012-04-09 20:13:28.311 [59501:12803] D restkit.network.queue:RKRequestQueue.m:320 Queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=YES requestCount=0 loadingCount=0/5> has been unsuspended | |
| 2012-04-09 20:13:28.331 [59501:12803] T restkit.network.reachability:RKReachabilityObserver.m:240 Reachability Flags: -R ------- | |
| 2012-04-09 20:13:28.338 [59501:12803] T restkit.network.reachability:RKReachabilityObserver.m:283 Reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=YES isMonitoringLocalWiFi=6651724 reachabilityFlags=-R -------> determined networkStatus = RKReachabilityReachableViaWiFi | |
| 2012-04-09 20:13:28.339 [59501:12803] D restkit.network.reachability:RKReachabilityObserver.m:297 Reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=YES isMonitoringLocalWiFi=6651724 reachabilityFlags=-R -------> determined isNetworkReachable = 1 | |
| 2012-04-09 20:13:55.162 [59501:12803] didSelectItem: Stores <UINavigationController: 0x85934f0> | |
| 2012-04-09 20:13:57.465 [59501:12803] T restkit.network.queue:RKRequestQueue.m:340 Request <RKObjectLoader: 0x92af7b0> added to queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=0 loadingCount=0/5> | |
| 2012-04-09 20:13:57.466 [59501:12803] T restkit.network.queue:RKRequestQueue.m:286 Processing request <RKObjectLoader: 0x92af7b0> in queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=1 loadingCount=0/5> | |
| 2012-04-09 20:13:57.467 [59501:12803] T restkit.network.queue:RKRequestQueue.m:201 Loading count increasing from 0 to 1. Firing requestQueueDidBeginLoading | |
| 2012-04-09 20:13:57.467 [59501:12803] T restkit.network.queue:RKRequestQueue.m:217 Loading count now 1 for queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=1 loadingCount=1/5> | |
| 2012-04-09 20:13:57.468 [59501:12803] D restkit.network.queue:RKRequestQueue.m:292 Sent request <RKObjectLoader: 0x92af7b0> from queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=1 loadingCount=1/5>. Loading count = 1 of 5 | |
| 2012-04-09 20:13:57.469 [59501:12803] T restkit.network.cache:RKRequestCache.m:86 Failed to find cacheKey for <RKObjectLoader: 0x92af7b0> due to nil cacheKey | |
| 2012-04-09 20:13:57.470 [59501:12803] T restkit.network.cache:RKRequestCache.m:98 Determined hasResponseForRequest: <RKObjectLoader: 0x92af7b0> => NO | |
| 2012-04-09 20:13:57.470 [59501:12803] T restkit.network.reachability:RKReachabilityObserver.m:240 Reachability Flags: -R ------- | |
| 2012-04-09 20:13:57.471 [59501:12803] T restkit.network.reachability:RKReachabilityObserver.m:283 Reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=YES isMonitoringLocalWiFi=6651724 reachabilityFlags=-R -------> determined networkStatus = RKReachabilityReachableViaWiFi | |
| 2012-04-09 20:13:57.473 [59501:12803] D restkit.network.reachability:RKReachabilityObserver.m:297 Reachability observer <RKReachabilityObserver: 0x9174280 host=XXX.XXX.XXX.XXX isReachabilityDetermined=YES isMonitoringLocalWiFi=6651724 reachabilityFlags=-R -------> determined isNetworkReachable = 1 | |
| 2012-04-09 20:13:57.474 [59501:12803] D restkit.network:RKRequest.m:435 Sending asynchronous POST request to URL http://XXX.XXX.XXX.XXX:9200/bbyopen_index/_search. | |
| 2012-04-09 20:13:57.474 [59501:12803] D restkit.network:RKObjectLoader.m:352 POST or PUT request for source object <ESBody: 0x9189f70>, serializing to MIME Type application/json for transport... | |
| 2012-04-09 20:13:57.475 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:617 Starting mapping operation... | |
| 2012-04-09 20:13:57.476 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:618 Performing mapping operation: RKObjectMappingOperation for '__NSCFDictionary' object. Mapping values from object <ESBody: 0x9189f70> to object { | |
| } with object mapping <RKObjectMapping:0x918ac60 objectClass=NSMutableDictionary keyPath mappings => ( | |
| "RKObjectKeyPathMapping: fields => fields", | |
| "RKObjectKeyPathMapping: query => query" | |
| )> | |
| 2012-04-09 20:13:57.511 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:322 Mapping attribute value keyPath 'fields' to 'fields' | |
| 2012-04-09 20:13:57.512 [59501:12803] D restkit.object_mapping:RKObjectPropertyInspector.m:107 Cached property names and types for Class 'NSMutableDictionary': { | |
| URLValue = NSString; | |
| accessibilityHint = NSString; | |
| accessibilityLabel = NSString; | |
| accessibilityLanguage = NSString; | |
| accessibilityValue = NSString; | |
| } | |
| 2012-04-09 20:13:57.512 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:332 Mapped attribute value from keyPath 'fields' to 'fields'. Value: ( | |
| name, | |
| upc | |
| ) | |
| 2012-04-09 20:13:57.513 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:564 Mapping one to one relationship value at keyPath 'query' to 'query' | |
| 2012-04-09 20:13:57.514 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:424 Performing nested object mapping using mapping RKObjectKeyPathMapping: query => query for data: <ESQuery: 0x918a6c0> | |
| 2012-04-09 20:13:57.515 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:617 Starting mapping operation... | |
| 2012-04-09 20:13:57.516 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:618 Performing mapping operation: RKObjectMappingOperation for '__NSCFDictionary' object. Mapping values from object <ESQuery: 0x918a6c0> to object { | |
| } with object mapping <RKObjectMapping:0x918ae70 objectClass=NSMutableDictionary keyPath mappings => ( | |
| "RKObjectKeyPathMapping: queryString => query_string" | |
| )> | |
| 2012-04-09 20:13:57.517 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:564 Mapping one to one relationship value at keyPath 'queryString' to 'query_string' | |
| 2012-04-09 20:13:57.517 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:424 Performing nested object mapping using mapping RKObjectKeyPathMapping: queryString => query_string for data: <ESQueryString: 0x91710a0> | |
| 2012-04-09 20:13:57.518 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:617 Starting mapping operation... | |
| 2012-04-09 20:13:57.519 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:618 Performing mapping operation: RKObjectMappingOperation for '__NSCFDictionary' object. Mapping values from object <ESQueryString: 0x91710a0> to object { | |
| } with object mapping <RKObjectMapping:0x918af00 objectClass=NSMutableDictionary keyPath mappings => ( | |
| "RKObjectKeyPathMapping: query => query", | |
| "RKObjectKeyPathMapping: useDisMax => use_dis_max" | |
| )> | |
| 2012-04-09 20:13:57.520 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:322 Mapping attribute value keyPath 'query' to 'query' | |
| 2012-04-09 20:13:57.520 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:332 Mapped attribute value from keyPath 'query' to 'query'. Value: +camera +laptop | |
| 2012-04-09 20:13:57.521 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:322 Mapping attribute value keyPath 'useDisMax' to 'use_dis_max' | |
| 2012-04-09 20:13:57.531 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:332 Mapped attribute value from keyPath 'useDisMax' to 'use_dis_max'. Value: 1 | |
| 2012-04-09 20:13:57.532 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:624 Finished mapping operation successfully... | |
| 2012-04-09 20:13:57.533 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:582 Mapped relationship object from keyPath 'queryString' to 'query_string'. Value: { | |
| query = "+camera +laptop"; | |
| "use_dis_max" = 1; | |
| } | |
| 2012-04-09 20:13:57.533 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:624 Finished mapping operation successfully... | |
| 2012-04-09 20:13:57.534 [59501:12803] T restkit.object_mapping:RKObjectMappingOperation.m:582 Mapped relationship object from keyPath 'query' to 'query'. Value: { | |
| "query_string" = { | |
| query = "+camera +laptop"; | |
| "use_dis_max" = 1; | |
| }; | |
| } | |
| 2012-04-09 20:13:57.535 [59501:12803] D restkit.object_mapping:RKObjectMappingOperation.m:624 Finished mapping operation successfully... | |
| 2012-04-09 20:13:57.536 [59501:12803] T restkit.network.cache:RKRequestCache.m:86 Failed to find cacheKey for <RKObjectLoader: 0x92af7b0> due to nil cacheKey | |
| 2012-04-09 20:13:57.537 [59501:12803] D restkit.network.cache:RKRequestCache.m:160 Unable to read cached headers for '<RKObjectLoader: 0x92af7b0>': cacheKey not found | |
| 2012-04-09 20:13:57.537 [59501:12803] D restkit.network.cache:RKRequestCache.m:176 Found cached ETag '(null)' for '<RKObjectLoader: 0x92af7b0>' | |
| 2012-04-09 20:13:57.538 [59501:12803] T restkit.network:RKRequest.m:381 Prepared POST URLRequest '<NSMutableURLRequest http://XXX.XXX.XXX.XXX:9200/bbyopen_index/_search>'. HTTP Headers: { | |
| Accept = "application/json"; | |
| "Content-Length" = 97; | |
| "Content-Type" = "application/json"; | |
| }. HTTP Body: {"query":{"query_string":{"query":"+camera +laptop","use_dis_max":true}},"fields":["name","upc"]}. | |
| 2012-04-09 20:13:57.539 [59501:12803] T restkit.network.queue:RKRequestQueue.m:248 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=1 loadingCount=1/5> | |
| (lldb) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2012-04-09 20:13:57.538 [59501:12803] T restkit.network:RKRequest.m:381 Prepared POST URLRequest '<NSMutableURLRequest http://XXX.XXX.XXX.XXX:9200/bbyopen_index/_search>'. HTTP Headers: { | |
| Accept = "application/json"; | |
| "Content-Length" = 97; | |
| "Content-Type" = "application/json"; | |
| }. HTTP Body: {"query":{"query_string":{"query":"+camera +laptop","use_dis_max":true}},"fields":["name","upc"]}. | |
| 2012-04-09 20:13:57.539 [59501:12803] T restkit.network.queue:RKRequestQueue.m:248 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x9171bd0 name=(null) suspended=NO requestCount=1 loadingCount=1/5> | |
| (lldb) | |
| EXC_BAD_ACCESS stops at this point in Xcode... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment