Posts

Showing posts with the label nested

Term, nested documents and must_not query incompatible in ElasticSearch?

Term, nested documents and must_not query incompatible in ElasticSearch? I have trouble combining term, must_not queries on nested documents. Sense example can be found here : http://sense.qbox.io/gist/be436a1ffa01e4630a964f48b2d5b3a1ef5fa176 Here my mapping : { "mappings": { "docs" : { "properties": { "tags" : { "type": "nested", "properties" : { "type": { "type": "string", "index": "not_analyzed" } } }, "label" : { "type": "string" } } } } } with two documents in this index : { "tags" : [ {"type" : "POST"},...

Convert python nested JSON-like data to dataframe

Convert python nested JSON-like data to dataframe My records looks like this and I need to write it to a csv file: my_data={"data":[{"id":"xyz","type":"book","attributes":{"doc_type":"article","action":"cut"}}]} which looks like json, but the next record starts with "data" and not "data1" which forces me to read each record separately. Then, I convert it to a dict using eval() , to iterate thru keys and values for a certain path to get to the values I need. Then, I generate a list of keys and values based on the keys I need. Then, a pd.dataframe() converts that list into a dataframe which I know how to convert to csv. My code that works is below. But I am sure there are better ways to do this. Mine scales poorly. Thx. "data" "data1" eval() pd.dataframe() counter=1 k= v= res= m=0 for line in f2: jline=eval(line) counter +=1 for items in jline...

Finding the sum of numbers in an array - excluding the number 13 and the number directly after it

Finding the sum of numbers in an array - excluding the number 13 and the number directly after it I would like to write a program in Java which, given an array, finds the sum of all the numbers in the array - with an exception! Since the number 13 is very unlucky, I propose that we shall completely exclude the number 13, and the number directly after 13, if it exists, from the total sum. The program, which I shall call sum13 , should produce the following results from the following inputs (these are just a few examples): sum13 sum13([1,2,2,1]) = 6 This one is normal; no 13's here. sum13([1,2,2,1]) = 6 sum13([5, 13, 2]) = 5 The 13 and the number directly after the 13 are excluded. sum13([5, 13, 2]) = 5 sum13([13, 13]) = 0 The array contains only 13's, so neither of them are included. sum13([13, 13]) = 0 sum13([1, 2, 13, 2, 1, 13]) = 4 A slightly longer example of the expected output. sum13([1, 2, 13, 2, 1, 13]) = 4 Here is the code which I came up with for sum13 : sum13 pu...