EmberFire and nested arrays - ember.js

I'm attempting my first ember-based project, as well as integrating emberfire into it to get Firebase capabilities. I'm building a tree menu builder, for another project.
The json for the firebase database is as follows:
{
"default" : {
"_type" : "arrayObject",
"name" : "unnamed",
"_name" : "default",
"menus" : {
"Top" : {
"menu" : {
"2" : {
"text" : "0-2",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 0,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : 0,
"a" : {
"_type" : "object"
},
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : 208,
"a" : {
"_type" : "object"
},
"r" : 208
},
"row" : 2,
"id" : 2
},
"5" : {
"text" : "0-5",
"actions" : [ {
"action" : 3
} ],
"column" : 0,
"color" : {
"b" : 0,
"g" : 0,
"a" : 255,
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : 208,
"g" : 208,
"a" : 255,
"r" : 208
},
"row" : 5,
"id" : 5
},
"12" : {
"text" : "1-3",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 3,
"id" : 12
},
"15" : {
"text" : "1-6",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 6,
"id" : 15
},
"8" : {
"text" : "0-8",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 0,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 8,
"id" : 8
},
"_type" : "objectArray",
"7" : {
"text" : "0-7",
"actions" : [ {
"action" : 3
} ],
"column" : 0,
"color" : {
"b" : 0,
"g" : 0,
"a" : 255,
"r" : 0
},
"_type" : "object",
"visibility" : "visible",
"page" : 0,
"bgColor" : {
"b" : 208,
"g" : 208,
"a" : 255,
"r" : 208
},
"row" : 7,
"id" : 7
},
"17" : {
"text" : "1-8",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 8,
"id" : 17
},
"1" : {
"text" : "0-1",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 0,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : 0,
"a" : {
"_type" : "object"
},
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : 208,
"a" : {
"_type" : "object"
},
"r" : 208
},
"row" : 1,
"id" : 1
},
"4" : {
"text" : "0-4",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3
}
},
"column" : 0,
"color" : {
"b" : 0,
"g" : 0,
"a" : 255,
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : 208,
"g" : 208,
"a" : 255,
"r" : 208
},
"row" : 4,
"id" : 4
},
"11" : {
"text" : "1-2",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 2,
"id" : 11
},
"14" : {
"text" : "1-5",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 5,
"id" : 14
},
"6" : {
"text" : "0-6",
"actions" : [ {
"action" : 3
} ],
"column" : 0,
"color" : {
"b" : 0,
"g" : 0,
"a" : 255,
"r" : 0
},
"_type" : "object",
"visibility" : "visible",
"page" : 0,
"bgColor" : {
"b" : 208,
"g" : 208,
"a" : 255,
"r" : 208
},
"row" : 6,
"id" : 6
},
"0" : {
"text" : "0-0",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 0,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : 208
},
"row" : 0,
"id" : "0"
},
"9" : {
"text" : "1-0",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 0,
"id" : 9
},
"16" : {
"text" : "1-7",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 7,
"id" : 16
},
"3" : {
"text" : "0-3",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 0,
"color" : {
"b" : 0,
"_type" : "objectArray",
"g" : 0,
"a" : {
"_type" : "object"
},
"r" : 0
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : 208,
"_type" : "objectArray",
"g" : 208,
"a" : {
"_type" : "object"
},
"r" : 208
},
"row" : 3,
"id" : 3
},
"10" : {
"text" : "1-1",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 1,
"id" : 10
},
"13" : {
"text" : "1-4",
"actions" : {
"_type" : "objectArray",
"0" : {
"action" : 3,
"_type" : "object"
}
},
"column" : 1,
"color" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"_type" : "object",
"visibility" : "hidden",
"page" : 0,
"bgColor" : {
"b" : {
"_type" : "object"
},
"_type" : "objectArray",
"g" : {
"_type" : "object"
},
"a" : {
"_type" : "object"
},
"r" : {
"_type" : "object"
}
},
"row" : 4,
"id" : 13
}
},
"_type" : "object"
},
"_type" : "objectArray"
},
"id" : "default"
},
"_type" : "objectArray",
"app2" : {
"_type" : "arrayObject",
"name" : "app2",
"_name" : "app2",
"menus" : {
"Top" : [ {
"text" : "0-0"
} ],
"_type" : "objectArray"
}
}
}
Anyhow, I've succeeded using a fork of emberFire that provides an emberFire object out of my initial array.(https://github.com/ember-meteor/emberFire/blob/refactor/emberfire-latest.js)
That works.
I have an embedded array that I turn into another emberFire ObjectArray, and
my code:https://github.com/jondthompson/menutest.
I used a similar behavior to the original ObjectArray creation to create a second one for the 'ssMenus' array nested within the 'ssApp', but it appears to not be populating with the proper data from Firebase, nor is the router even firing with an empty array.
The proper behavior would be when you click on an 'app', the name of the app appears at the bottom (works!), with the names of the menus appearing next to it (doesn't).
Anyhow, Help, please!

I figured it out.
I was writing the child firebase reference manually. I figured out how to do it via the original firebase object.
I wasn't encapsulating the child reference in a firebase object, but rather I was trying to inject it somewhere it didn't belong.
I was trying to create a second route, when I didn't need it.
I may have missed something else too. I consider myself a beginner programmer, so this is stretching my abilities.
My original AppController..
App.SsAppController = Ember.ObjectController.extend({
needs: ["selected_ssApp", 'ssMenus'],
selected: function(){
return this.get('controllers.selected_ssApp.model') === this.get('model');
}.property('controllers.selected_ssApp.model', 'model'),
actions: {
select: function(){
var model = this.get('model');
var menuList = this.get('controllers.ssMenus')
Ember.debug("MenuList: "+ menuList);
this.set('controllers.selected_ssApp.model', model);
menuList.set('ref', new Firebase("https://menutest.firebaseio.com/jt-test/"+model.content._name+"/menus"));
}
}
});
My new and improved (read: working) MenuController..
App.SsAppController = Ember.ObjectController.extend({
needs: ["selected_ssApp", 'ssMenus'],
menus: function(){
var model = this.get('model'),
ref = model.get('ref');
return EmberFire.ObjectArray.create({ ref: ref.child('menus')});
},
selected: function(){
return this.get('controllers.selected_ssApp.model') === this.get('model');
}.property('controllers.selected_ssApp.model', 'model'),
actions: {
select: function(){
var model = this.get('model'),
menusObj = model.get('menus');
this.set('controllers.selected_ssApp.model', model);
this.set('controllers.ssMenus.content', this.menus());
}
}
});

Related

AWS Elasticsearch OpenDistro -Rollover is not triggered with elasticsearch on min_doc_count/ min_index_age

State management policy
{
"policy_id": "my_policy",
"description": "Example rollover policy.",
"last_updated_time": 1657880963669,
"schema_version": 1,
"error_notification": null,
"default_state": "rollover",
"states": [
{
"name": "rollover",
"actions": [
{
"rollover": {
"min_doc_count": 3
}
}
],
"transitions": []
}
],
"ism_template": [
{
"index_patterns": [
"aggregation*"
],
"priority": 100,
"last_updated_time": 1657875922756
}
]
}
Index Template
PUT _index_template/ism_rollover
{
"index_patterns": ["aggregation*"],
"template": {
"settings": {
"index.opendistro.index_state_management.rollover_alias": "aggregation"
}
}
}
Initial Mapping
PUT aggregation-000001
{
"aliases": {
"aggregation": {
"is_write_index": true
}
}
}
Inserted Multiple Documents All are going to aggregation-000001
GET /aggregation/_search
{
"query": {
"match_all": {}
}
}
Giving Results:
{
"_index" : "aggregation-000001",
"_type" : "_doc",
"_id" : "8gYkAYIBU-tV46puNpjC",
"_score" : 1.0,
"_source" : {
"message" : "Ra First Doc"
}
},
{
"_index" : "aggregation-000001",
"_type" : "_doc",
"_id" : "7",
"_score" : 1.0,
"_source" : {
"message" : "vcxv"
}
},
{
"_index" : "aggregation-000001",
"_type" : "_doc",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"message" : "fdff"
}
},
{
"_index" : "aggregation-000001",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"message" : "checker"
}
}
]
Please Let me know if I'm missing somthing.

GroupBy on a partition then count in Opensearch: Group By on multiple fields

I have the following data
{
"companyID" : "amz",
"companyType" : "ret",
"employeeID" : "ty-5a62fd78e8d20ad"
},
{
"companyID" : "amz",
"companyType" : "ret",
"employeeID" : "ay-5a62fd78e8d20ad"
},
{
"companyID" : "mic",
"companyType" : "cse",
"employeeID" : "by-5a62fd78e8d20ad"
},
{
"companyID" : "ggl",
"companyType" : "cse",
"employeeID" : "ply-5a62fd78e8d20ad"
},
{
"companyID" : "ggl",
"companyType" : "cse",
"employeeID" : "wfly-5a62ad"
}
I want the following result. basically combination of values like this mic-cse,ggl-cse,amz-ret .
"agg_by_company_type" : {
"buckets" : [
{
"key" : "ret",
"doc_count" : 1
},
{
"key" : "cse",
"doc_count" : 2
}
]
How do I do it?
I have tried the following aggregations:
"agg_by_companyID_topHits": {
"terms": {
"field": "companyID.keyword",
"size": 100000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": true,
"order": {
"_key": "asc"
}
},
"aggs": {
"agg_by_companyType" : {
"top_hits": {
"size": 1,
"_source": {
"includes": ["companyType"]
}
}
}
}
}
But this just gives me first groupBy of company id now on top of that data I want count of company type.
this is the response I get
"agg_by_companyID_topHits" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "amz",
"doc_count" : 2,
"doc_count_error_upper_bound" : 0,
"agg_by_companytype" : {
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "uytuygjuhg",
"_score" : 0.0,
"_source" : {
"companyType" : "ret"
}
}
]
}
}
},
{
"key" : "mic",
"doc_count" : 1,
"doc_count_error_upper_bound" : 0,
"agg_by_companytype" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "uytuygjuhg",
"_score" : 0.0,
"_source" : {
"companyType" : "cse"
}
}
]
}
}
},
{
"key" : "ggl",
"doc_count" : 2,
"doc_count_error_upper_bound" : 0,
"agg_by_companytype" : {
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "uytuygjuhg",
"_score" : 0.0,
"_source" : {
"companyType" : "ret"
}
}
]
}
}
},
]
}
If it were spark, it would be simple to partition by companyID, group it and then group by companyType and count to get the desired result but not sure how to do it in ES.
Important Note: I am working with Opensearch.
Possible solution for this in elastic search multi-terms-aggregation
is not available in versions before v7.12.
So wondering how it was done before this feature in ES.
We came across this issue because AWS migrated from ES to Opensearch.
use multi_terms agg doc here
GET /products/_search
{
"aggs": {
"genres_and_products": {
"multi_terms": {
"terms": [{
"field": "companyID"
}, {
"field": "companyType"
}]
}
}
}
}
can you use script in terms agg ,like this:
GET b1/_search
{
"aggs": {
"genres": {
"terms": {
"script": {
"source": "doc['companyID'].value+doc['companyType'].value",
"lang": "painless"
}
}
}
}
}

MongoDB - find count of field in nested document

I want to find the count of all occurrences of the field "36" from the the following json:
The count should be 2. The field is present in any of the data.TL.TXXX documents.
I tried the find() method of mongoDB, but could only search in one document at a time. Probably I need a regex here. Can someone help me out:
{
"_id" : ObjectId("1115dd31af82eb3ca8028188"),
"data" : {
"TL" : {
"T001" : {
"11" : "05012017",
"13" : "0",
"28" : "000",
"29" : "00000",
"30" : "01012017",
"31" : "01122014",
"36" : "10000",
"37" : "3000",
"38" : "29.81",
"39" : "1",
"44" : "03",
"02" : "NOT DISCLOSED",
"04" : "10",
"05" : "1",
"08" : "16122014"
}
}
}
},
{
"_id" : ObjectId("345222ddaf82eb1b262be44f"),
"data" : {
"TL" : {
"T004" : {
"10" : "19052013",
"11" : "15062013",
"12" : "37903",
"13" : "0",
"28" : "00000000",
"29" : "000000000000000000",
"30" : "01052013",
"31" : "01062011",
"44" : "03",
"02" : "NOT DISCLOSED",
"04" : "10",
"05" : "1",
"08" : "27062011",
"09" : "08052013"
},
"T005" : {
"11" : "10012017",
"12" : "114525",
"13" : "8853",
"28" : "00000300000300000",
"29" : "000000XXX0000000010",
"30" : "01012017",
"31" : "01022014",
"36" : "100000",
"37" : "10000",
"44" : "03",
"45" : "6714",
"02" : "NOT DISCLOSED",
"04" : "10",
"05" : "1",
"08" : "27062011",
"09" : "12122016"
},
}
}
}
You can use below aggregation
db.collection.aggregate([
{ $project: { "data.TL": { $objectToArray: "$data.TL" }}},
{ $unwind: "$data.TL" },
{ $project: { data: { $objectToArray: "$data.TL.v" }}},
{ $unwind: "$data" },
{ $group: { _id: "$data.k", count: { $sum: 1 }}}
]);
MongoPlayground

Elastic Search only matches full field

I have just started using Elastic Search 6 on AWS.
I have inserted data into my ES endpoint but I can only search it using the full sentence and not match individual words. In the past I would have used not_analyzed it seems, but this has been replaced by 'keyword'. However this still doesn't work.
Here is my index:
{
"seven" : {
"aliases" : { },
"mappings" : {
"myobjects" : {
"properties" : {
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"myId" : {
"type" : "text"
},
"myUrl" : {
"type" : "text"
},
"myName" : {
"type" : "keyword"
},
"myText" : {
"type" : "keyword"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "5",
"provided_name" : "seven",
"creation_date" : "1519389595593",
"analysis" : {
"filter" : {
"nGram_filter" : {
"token_chars" : [
"letter",
"digit",
"punctuation",
"symbol"
],
"min_gram" : "2",
"type" : "nGram",
"max_gram" : "20"
}
},
"analyzer" : {
"nGram_analyzer" : {
"filter" : [
"lowercase",
"asciifolding",
"nGram_filter"
],
"type" : "custom",
"tokenizer" : "whitespace"
},
"whitespace_analyzer" : {
"filter" : [
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "whitespace"
}
}
},
"number_of_replicas" : "1",
"uuid" : "_vNXSADUTUaspBUu6zdh-g",
"version" : {
"created" : "6000199"
}
}
}
}
}
I have data like this:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 13,
"max_score" : 1.0,
"hits" : [
{
"_index" : "seven",
"_type" : "myobjects",
"_id" : "8",
"_score" : 1.0,
"_source" : {
"myUrl" : "https://myobjects.com/wales.gif",
"myText" : "Objects for Welsh Things",
"myName" : "Wales"
}
},
{
"_index" : "seven",
"_type" : "myobjects",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"myUrl" : "https://myobjects.com/flowers.gif",
"myText" : "Objects for Flowery Things",
"myNoun" : "Flowers"
}
}
]
}
}
If I then search for 'Objects' I get nothing. If I search for 'Objects for Flowery Things' I get the single result.
I am using this to search for items :
POST /seven/objects/_search?pretty
{
"query": {
"multi_match" : { "query" : q, "fields": ["myText", "myNoun"], "fuzziness":"AUTO" }
}
}
Can anybody tell me how to have the search match any word in the sentence rather than having to put the whole sentence in the query?
This is because your myName and myText fields are of keyword type:
...
"myName" : {
"type" : "keyword"
},
"myText" : {
"type" : "keyword"
}
...
and because of this they are not analyzed and only full match will work for them. Change the type to text and it should work as you expected:
...
"myName" : {
"type" : "text"
},
"myText" : {
"type" : "text"
}
...

Parsing text for elasticsearch index and grab index values

In the parts below, I need to pick out the first entry of the output for each section which in turn is the name of the index for ElasticSearch.
For instance nprod#n_docs, platform-api-stage, nprod#janeuk_classic, nprod#delista.com#1
So I know that they are between patterns of characters like
{ "
and a
: {
"settings" : {
So what would my script look like to grab these values so I can cat them out to another file?
My output looks like:
{
"nprod#n_docs" : {
"settings" : {
"index.analysis.analyzer.rwn_text_analyzer.char_filter" : "html_strip",
"index.analysis.analyzer.rwn_text_analyzer.language" : "English",
"index.translog.disable_flush" : "false",
"index.version.created" : "190199",
"index.number_of_replicas" : "1",
"index.number_of_shards" : "5",
"index.analysis.analyzer.rwn_text_analyzer.type" : "snowball",
"index.translog.flush_threshold_size" : "60",
"index.translog.flush_threshold_period" : "",
"index.translog.flush_threshold_ops" : "500"
}
},
"platform-api-stage" : {
"settings" : {
"index.analysis.analyzer.api_edgeNGram.type" : "custom",
"index.analysis.analyzer.api_edgeNGram.filter.0" : "api_nGram",
"index.analysis.filter.api_nGram.max_gram" : "50",
"index.analysis.analyzer.api_edgeNGram.filter.1" : "lowercase",
"index.analysis.analyzer.api_path.type" : "custom",
"index.analysis.analyzer.api_path.tokenizer" : "path_hierarchy",
"index.analysis.filter.api_nGram.min_gram" : "2",
"index.analysis.filter.api_nGram.type" : "edgeNGram",
"index.analysis.analyzer.api_edgeNGram.tokenizer" : "standard",
"index.analysis.filter.api_nGram.side" : "front",
"index.analysis.analyzer.api_path.filter.0" : "lowercase",
"index.number_of_shards" : "5",
"index.number_of_replicas" : "1",
"index.version.created" : "200599"
}
},
"nprod#janeuk_classic" : {
"settings" : {
"index.analysis.analyzer.n_text_analyzer.language" : "English",
"index.translog.disable_flush" : "false",
"index.version.created" : "190199",
"index.number_of_replicas" : "1",
"index.number_of_shards" : "5",
"index.analysis.analyzer.n_text_analyzer.char_filter" : "html_strip",
"index.analysis.analyzer.n_text_analyzer.type" : "snowball",
"index.translog.flush_threshold_size" : "60",
"index.translog.flush_threshold_period" : "",
"index.translog.flush_threshold_ops" : "500"
}
},
"nprod#delista.com#1" : {
"settings" : {
"index.analysis.analyzer.n_text_analyzer.language" : "English",
"index.translog.disable_flush" : "false",
"index.version.created" : "191199",
"index.number_of_replicas" : "1",
"index.number_of_shards" : "5",
"index.analysis.analyzer.n_text_analyzer.char_filter" : "html_strip",
"index.analysis.analyzer.n_text_analyzer.type" : "snowball",
"index.translog.flush_threshold_size" : "60",
"index.translog.flush_threshold_period" : "",
"index.translog.flush_threshold_ops" : "500"
}
},
That's JSON. Read the data and parse it using JSON::XS.
use JSON::XS qw( decode_json );
my $file;
{
open(my $fh, '<:raw', $qfn)
or die("Can't open \"$qfn\": $!\n");
local $/;
$file = <$fh>;
}
my $data = decode_json($file);
Then, just traverse the tree for the information you want.
my #index_names = keys(%$data);