nested

ElasticSearch: access document nested value in groovy script

懵懂的女人 提交于 2019-12-04 11:47:06
问题 I have a document stored in ElasticSearch as below. _source: { "firstname": "John", "lastname": "Smith", "medals":[ { "bucket": 100, "count": 1 }, { "bucket": 150, "count": 2 } ] } I can access the string type value inside a document using doc.firstname for scripted metric aggregation http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html. But I am not able to get the field value using doc.medals[0].bucket. Can you

Is there a way to get the function a decorator has wrapped?

余生颓废 提交于 2019-12-04 11:32:57
Suppose I have @someDecorator def func(): '''this function does something''' print 1 Now, the object func is an instance of someDecorator . Is there some way I can access the function it holds, i.e something like func.getInnerFunction() . For instance, if I need to retrieve the doc string of func() . See functools.wraps: http://docs.python.org/library/functools.html . The decorator gets the name and doc string of the original function. You use it like this: def decorator(f): @functools.wraps(f) def wrapper(): .... SilentGhost and sri have partial answers for how to deal with this. But the

Creating Multidimensional Nested Array from MySQL Result with Duplicate Values (PHP)

≡放荡痞女 提交于 2019-12-04 10:21:26
I currently am pulling menu data out of our database using the PDO fetchAll() function. Doing so puts each row of the query results into an array in the following structure: Array ( [0] => Array ( [MenuId] => mmnlinlm08l6r7e8ju53n1f58 [MenuName] => Main Menu [SectionId] => eq44ip4y7qqexzqd7kjsdwh5p [SubmenuName] => Salads & Appetizers [ItemName] => Tomato Salad [Description] => Cucumbers, peppers, scallions and cured tuna [Price] => $7.00) [1] => Array ( [MenuId] => mmnlinlm08l6r7e8ju53n1f58 [MenuName] => Main Menu [SectionId] => xlkadsj92laada9082lkas [SubmenuName] => Entrees [ItemName] =>

Create nested json with c#

旧城冷巷雨未停 提交于 2019-12-04 10:05:30
I am able to create a flat serialized JSON string pretty easily with c# My issue is I want to create a nested string like this below [ { title: "Yes", id : "1", menu: [ { title: "Maybe", id : "3", alert : "No", menu: [ { title: "Maybe Not", id : "8", alert : "No", menu: [] } ] } ] }, { title: "No", id : "2", menu: [] }] Any help would be great Are you using MVC 3? - Do something like: return Json(myObectWithListProperties, JsonRequestBehavior.AllowGet); I use this to return complex C# objects that match the structure of the JavaScript objects I want. e.g.: var bob = new { name = "test", orders

Haskell - Does a replace function exist?

故事扮演 提交于 2019-12-04 09:54:34
I have to make three functions for replacing of flat strings and in lists. I don't know, whether there is a replace function like in other languages. I searched for that however unfortunately without success :-( So my attempt is yet quite thin. 1st function: replace :: String -> String -> String -> String replace findStr replaceStr myText = replace()?? My approach for the 1st function: replace :: String -> String -> String -> String replace [] old new = [] replace str old new = loop str where loop [] = [] loop str = let (prefix, rest) = splitAt n str in if old == prefix -- found an occurrence?

Passing compile-time state between nested macros in Clojure

房东的猫 提交于 2019-12-04 09:36:05
I'm trying to write a macro that can be used both in a global and nested way, like so: ;;; global: (do-stuff 1) ;;; nested, within a "with-context" block: (with-context {:foo :bar} (do-stuff 2) (do-stuff 3)) When used in the nested way, do-stuff should have access to {:foo :bar} set by with-context . I've been able to implement it like this: (def ^:dynamic *ctx* nil) (defmacro with-context [ctx & body] `(binding [*ctx* ~ctx] (do ~@body))) (defmacro do-stuff [v] `(if *ctx* (println "within context" *ctx* ":" ~v) (println "no context:" ~v))) However, I've been trying to shift the if within do

RESTfully Nesting Resource Routes with Single Identifiers

。_饼干妹妹 提交于 2019-12-04 09:31:10
问题 In my Rails app I have a fairly standard has_many relationship between two entities. A Foo has zero or more Bars ; a Bar belongs to exactly one Foo . Both Foo and Bar are identified by a single integer ID value. These values are unique across all of their respective instances. Bar is existence dependent on Foo: it makes no sense to have a Bar without a Foo. There's two ways to RESTfully references instances of these classes. Given a Foo.id of "100" and a Bar.id of "200": Reference each Foo

Scrapy with a nested array

◇◆丶佛笑我妖孽 提交于 2019-12-04 08:59:01
I'm new to scrapy and would like to understand how to scrape on object for output into nested JSON. Right now, I'm producing JSON that looks like [ {'a' : 1, 'b' : '2', 'c' : 3}, ] And I'd like it more like this: [ { 'a' : '1', '_junk' : [ 'b' : 2, 'c' : 3]}, ] ---where I put some stuff in _junk subfields to post-process later. The current code under the parser definition file in my scrapername.py is... item['a'] = x item['b'] = y item['c'] = z And it seemed like item['a'] = x item['_junk']['b'] = y item['_junk']['c'] = z ---might fix that, but I'm getting an error about the _junk key: File "

How do I show nested data into a tree?

独自空忆成欢 提交于 2019-12-04 08:36:55
问题 Further progress. Please see at http://www.sencha.com/forum/showthread.php?153986-Empty-column-something-I-can-t-get-with-Ext.data.TreeStore-and-or-Ext.tree.Panel I always appreciate any further advise. I am trying to develop a simple extJS Ext 4.0.2a script to display some nested data as a Drag&Drop tree. To try, I use a simple example from http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Reader Data are given as a users.json file: { "users": [ { "id": 123, "name": "Ed", "orders": [

syntax error in if…else condition

别来无恙 提交于 2019-12-04 07:22:13
问题 I'm learning programming in Python and I'm stuck with a syntax error in the line 8 in the following code x = int(input('Add x:\n')) y = int(input('Add y:\n')) if x == y : print('x and y are equal') else : if x < y : print('x is less than y') else x > y : print('x is greater than y') I just don't see what's wrong there. The full error is: Traceback (most recent call last): File "compare.py", line 8 else x > y : ^ SyntaxError: invalid syntax 回答1: else takes no condition. It's just else: ,