Modification/anomaly between ES versions 7.10.2 and 7.16.3? - linux

The following mapping and query DSL dict work OK when the version of ES is 7.10.2, but they never work where the version of ES is 7.16.3:
mappings = \
{
"mappings": {
"properties": {
"esdoc_text": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"stemmed": {
"type": "text",
"analyzer": "english",
"term_vector": "with_positions_offsets",
}
}
}
}
}
}
search dict:
data = \
{
'query': {
'simple_query_string': {
'query': self.search_string,
'fields': [
self.text_field
]
}
},
'highlight': {
'fields': {
self.text_field: {
'type': 'fvh',
'pre_tags': [
'<span style="background-color: yellow">',
'<span style="background-color: skyblue">',
'<span style="background-color: lightgreen">',
'<span style="background-color: plum">',
'<span style="background-color: lightcoral">',
'<span style="background-color: silver">',
],
'post_tags': [
'</span>', '</span>', '</span>',
'</span>', '</span>', '</span>',
]
}
},
'number_of_fragments': 0
}
}
with version 7.10.2, setting self.text_field to "esdoc_text" (field name) returns highlighted results using a standard analyser, and setting self.text_field to "esdoc_text.stemmed" returns highlighted results using an english analyser.
but with version 7.16.3, with the identical mapping and identical query DSL dict, hits are produced, but they never contain a "highlight" key.
Has anyone got any idea why this might be? Has any modification crept in between 7.10.2 and 7.16.3 which might explain this? Anyone now how to change things?

Related

How to extract selected key and value from nested dictionary object in a list?

I have a list example_list contains two dict objects, it looks like this:
[
{
"Meta": {
"ID": "1234567",
"XXX": "XXX"
},
"bbb": {
"ccc": {
"ddd": {
"eee": {
"fff": {
"xxxxxx": "xxxxx"
},
"www": [
{
"categories": {
"ppp": [
{
"content": {
"name": "apple",
"price": "0.111"
},
"xxx: "xxx"
}
]
},
"date": "A2020-01-01"
}
]
}
}
}
}
},
{
"Meta": {
"ID": "78945612",
"XXX": "XXX"
},
"bbb": {
"ccc": {
"ddd": {
"eee": {
"fff": {
"xxxxxx": "xxxxx"
},
"www": [
{
"categories": {
"ppp": [
{
"content": {
"name": "banana",
"price": "12.599"
},
"xxx: "xxx"
}
]
},
"date": "A2020-01-01"
}
]
}
}
}
}
}
]
now I want to filter the items and only keep "ID": "xxx" and the correspoding value for "price": "0.111", expected result can be something similar to :
[{"ID": "1234567", "price": "0.111"}, {"ID": "78945612", "price": "12.599"}]
or something like {"1234567":"0.111", "78945612":"12.599" }
Here's what I've tried:
map_list=[]
map_dict={}
for item in example_list:
#get 'ID' for each item in 'meta'
map_dict['ID'] = item['meta']['ID']
# get 'price'
data_list = item['bbb']['ccc']['ddd']['www']
for data in data_list:
for dataitem in data['categories']['ppp']
map_dict['price'] = item["content"]["price"]
map_list.append(map_dict)
print(map_list)
The result for this doesn't look right, feels like the item isn't iterating properly, it gives me result:
[{"ID": "78945612", "price": "12.599"}, {"ID": "78945612", "price": "12.599"}]
It gave me duplicated result for the second ID but where is the first ID?
Can someone take a look for me please, thanks.
Update:
From some comments from another question, I understand the reason for the output keeps been overwritten is because the key name in the dict is always the same, but I'm not sure how to fix this because the key and value needs to be extracted from different level of for loops, any help would be appreciated, thanks.
as #Scott Hunter has mentioned, you need to create a new map_dict everytime you are trying to do this. Here is a quick fix to your solution (I am sadly not able to test it right now, but it seems right to me).
map_list=[]
for item in example_list:
# get 'price'
data_list = item['bbb']['ccc']['ddd']['www']
for data in data_list:
for dataitem in data['categories']['ppp']:
map_dict={}
map_dict['ID'] = item['meta']['ID']
map_dict['price'] = item["content"]["price"]
map_list.append(map_dict)
print(map_list)
But what are you doing here is that you are basically just "forcing" your way through ... I recommend you to take a break and check out somekind of tutorial, which will help you to understand how it really works in the back-end. This is how I would have written it:
list_dicts = []
for example in example_list:
for www in item['bbb']['ccc']['ddd']['www']:
for www_item in www:
list_dicts.append({
'ID': item['meta']['ID'],
'price': www_item["content"]["price"]
})
Good luck with this problem and hope it helps :)
You need to create a new dictionary for map_dict for each ID.

Working example to custom-format a column title/header?

I have a formatter that works for column data, using column parameter formatter. Using the same formatter with column parameter titleformatter, I get the error noted below. Also, I don't understand why HTML in title parameter text seems not to work for <b> ... </b> but does work for other things (e.g., <i> ... </i>. A working custom formatter example would help. (I don't see this in Tabulator documentation.) See this montage combining a column header and row header screenshot with common cell text---'bold' in the row looks bolder to me.
Cell text comparison screenshot montage
I've tried emulating some posted sample code, but I get the same error as reported by #dagroj in his comment to #Oli Folkerd's answer (to the question) about titleformatter --- viz. tabulator.min.js:2 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. (Mentioning that here because I don't yet have the reputation to comment there.)
Here is a rendering of my CPT, without the titleformatter.
Corresponding table constructor:
"columnVertAlign": "bottom",
"height": "100%",
"layout": "fitColumns",
"columns": [
{
"title": "<i> absolute_T<--T (noisyAnd)</i>",
"columns": [
{
"title": "<b> NotCorrAnd_EffectiveHyp</b>",
"field": "label",
"align": "right",
"headerSort": false
}
]
},
{
"title": "NotB_EffectiveHyp",
"columns": [
{
"title": "<b>T</B>",
"field": "true",
"align": "center",
"headerSort": false
},
{
"title": "<i>F</i>",
"field": "false",
"align": "center",
"headerSort": false
}
]
},
{
"title": "<b> Belief </b>",
"columns": [
{
"title": "odds",
"field": "odds",
"align": "center",
"headerSort": false
},
{
"title": "log<sub>2</sub> odds",
"field": "log2odds",
"align": "center",
"headerSort": false
}
]
}
]
}
Formatter:
function truthFormatter(cell, formatterParams, onRendered) {
var cellValue = cell.getValue();
var cellElement = cell.getElement();
if (cellValue == "T") {
cellElement.style.backgroundColor = "#0000B3";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else if (cellValue == "F") {
cellElement.style.backgroundColor = "#B30000";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else cellElement.style.color = "#000000";
return cell.getValue();
}
Column headers are by default styled to be bold, so adding a bold or strong tag will not make them any bolder. On a side not you are using a mix of lowercase and uppercase "b" in your tags
If you are getting that error it means that your formatter is not returning a valid value, it must either be a string/number or a DOM element of type Node.

Zingchart how to add custom legend item

I have a bar chart with 3 kinds of bar: FOO, BAR and BAZ.
Horizontal axis are quarters.
BAR and BAZ use the same series. BAR (blue) becoming BAZ (orange) after Q1-17.
"rules": [{
"rule": "%kv > 1",
"background-color":"orange"
}]
How can I add BAZ (orange) to the legend?
zingchart.THEME = "classic";
var myConfig = {
"graphset": [{
"type": "bar",
"background-color": "white",
"plotarea": {
"margin": "80 60 100 60",
"y": "125px"
},
"legend": {
"layout": "x3",
"y": "13%",
"x": "34.5%",
"overflow": "page",
"toggle-action": "remove",
},
"scale-x": {
"labels": [
"Q4-16",
"Q1-17",
"Q2-17",
"Q3-17"
],
"markers": [{
"value-range": true,
"range": [1.5],
"line-color": "red",
"line-width": 1,
"line-style": "solid",
"type": "line"
}]
},
"series": [{
"values": [
37.47,
57.59,
45.65,
37.43
],
"background-color": "#8993c7",
"text": "FOO"
},
{
"values": [
13.4,
14.11,
14.89,
16.86
],
"background-color": "blue",
"text": "BAR",
"rules": [{
"rule": "%kv > 1",
"background-color": "orange"
}]
}
]
}]
};
zingchart.render({
id: 'myChart',
data: myConfig,
height: 500,
width: 725
});
.zc-ref {
display: none;
}
<html>
<head>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script>
zingchart.MODULESDIR = "https://cdn.zingchart.com/modules/";
ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "ee6b7db5b51705a13dc2339db3edaf6d"];
</script>
</head>
<body>
<div id='myChart'><a class="zc-ref" href="https://www.zingchart.com/">Charts by ZingChart</a></div>
</body>
</html>
So one way to do it is split up your data. The easiest way to explain this is to make another series for "BAZ" and in the first two quarters have null values.
demo here
The main reason for doing it this way is maintaining the built in legend toggling functionality. This way when you click it wont turn off the whole series (blue and orange bars.) Which I assume is the intended functionality.
If you don't mind turning off blue and orange bars at the same time you can do the following to add another legend item. Add the text and color inside the series object. Essentially, create a blank series object.
...{
"text":"BAZ",
"background-color":"orange"
}...
non interactive legend demo here
If you are looking for something in between these two demos it will take some custom Javascript using the ZingChart API.

angularJS Search models

I'm new to angularJS. I have a requirement to perform a search on JSON data. Here is an example JSON structure
countries = [
{
"country_name" : "India",
"stations" : [
{
"name": "Dream Factory"
}
]
},
{
"country_name" : "Indonesia",
"stations" : [
{
"name": "Drummer Factory"
},
{
"name": "Beats"
}
]
}
]
Say I type Ind, I need the countries matching the string and return both India and Indonesia
also In other field, typing Factory should retrieve station names which matches the string (here Drummer Factory, Dream Factory).
What is the simple way to achieve this?
Is there any built-in directive which solves this or can I use filters, If yes, please post with example...
You can use the filter named 'filter' (yes it's a little confusing): http://docs.angularjs.org/api/ng.filter:filter
Here's a demo: http://jsfiddle.net/g/pXnRs/4/
HTML:
<div ng-controller="CountryController">
Filter: <input ng-model="nameFilter" />
<ul>
<li ng-repeat="country in countries | filter: nameFilter">
{{country | json}}
</li>
</ul>
</div>​
JS:
var app = angular.module('app', []);
app.controller('CountryController', function($scope){
$scope.nameFilter = '';
$scope.countries = [
{
"country_name" : "India",
"stations" : [
{
"name": "Dream Factory"
}
]
},
{
"country_name" : "Indonesia",
"stations" : [
{
"name": "Drummer Factory"
},
{
"name": "Beats"
}
]
}];
});
angular.bootstrap(document, ['app']);
If you need stations only as results, you should first flatten the JSON object hierarchy into a list of stations.
​

node.js jade - Unable to access nested array elements

Sorry if this is a really basic question, but I cannot find any examples similar to the issue I am trying to solve.
Can somebody please explain why I am not able to access a nested array of elements in the following code and also how I can access elements from that array? From the json below, I am not able to get at the "Items" array found from the second result on.
The following json is being returned:
{
"d": {
"results": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"__index": 1,
"ID": "someID1",
"Name": "Some Name 1"
},
{
"__index": 2,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID2_1",
"Name": "Item 2_1"
}
]
},
{
"__index": 3,
"Items": [
{
"__metadata": {
"uri": "...",
"type": "..."
},
"ID": "itemID3_1",
"Name": "Item 3_1"
}
]
},
...
Here is the jade layout:
- var results=records, col_type='even';
table#results(style="border-collapse:collapse;")
tr
th.result-header Index
th.result-header ID
th.result-header Name
- each r in results
- col_type=col_type=='even' ? 'odd' : 'even'
tr.result-row
- if (!r.Items)
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.Name}
- else
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{r.__index}
- each i in r.Items
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.ID}
td(class='result-col-'+col_type,style="border-left:1px solid black")
#{i.Name}
The issue here is that your JSON is in this format
{
"d": {
"results": [
...
]
So you need to change this part in your jade template from
- each r in results
- col_type=col_type=='even' ? 'odd' : 'even'
to this,
- each r in results['d']['results']
- col_type=col_type=='even' ? 'odd' : 'even'
This way, your loop will be pass through each array item.
so I just ran across the same problem. My solution was to do:
- each r in results
- each i in r.Items
"... do stuff with i"

Resources