using Nest DateRange - elasticsearch

Using this example, I came up with the following query. I don't get any results from this, but if I replace "01/01/2017" with 'null' then I get records (all from 2014 so i know it should be returning data). Can anyone help me please?
var response = elasticClient.Search<AnalyticsFormData>(x => x
.Type("formdata")
.Size(500)
.Query(q => q.Bool(b => b.Must
(mu => mu.MatchPhrase(m => m
.Field(f => f.AppId)
.Query(input.FormAppId)))
.Filter(fi => fi
.DateRange(r => r
.Field(f => f.LastUpdated)
.LessThanOrEquals(DateMath.Anchored("01/01/2017"))))))
.Sort(s => s.Ascending(f => f.LastUpdated)));

Either you have an incorrect field mapping, or incorrect date format. Try the following:
Create a new index with automapping
elasticClient.CreateIndex(indexName,
create => create.Mappings(
mappings => mappings.Map<AnalyticsFormData>(map => map.AutoMap())
)
);
Use the following approach to set the date
var response = client.Search<AnalyticsFormData>(x => x
.Size(500)
.Query(q => q.Bool(b => b.Must
(mu => mu.MatchPhrase(m => m
.Field(f => f.AppId).Query("FormAppId")))
.Filter(fi => fi
.DateRange(r => r
.Field(f => f.LastUpdated)
.LessThanOrEquals(new DateTime(2017, 1, 1))))))
.Sort(s => s.Ascending(f => f.LastUpdated)));

Related

Elastic Nest Html Strip on Automapp

Hopefully a quick one I am automapping my Index and I just want to universally strip html from any field is this possible I have tried this
var des = new CreateIndexDescriptor("myindex")
.Settings(s =>s
.Analysis(a => a
.CharFilters(c => c.HtmlStrip("product"))))
.Mappings(ms => ms
.Map<Product>(m => m
.Properties(ps => ps
.Nested<ProductSpecification>(n => n
.Name(c => c.ProductSpecification)
.Properties(psp => psp
.Keyword(s => s
.Name(ps1 => ps1.Name)
)
.Keyword(s => s
.Name(ps1 => ps1.Value)
)
)
)
).AutoMap()
));

Getting data from Laravel Collection

I realize this is a dumb question, but I can't find an answer for it. I am missing some understanding around how collections work
I am querying a google places API for information about a location
$response = GooglePlaces::textSearch('10 Downing Street', $optionnalParameters);
This works and gives me a response, which I can var_export:
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
'html_attributions' =>
array (
),
'results' =>
Illuminate\Support\Collection::__set_state(array(
'items' =>
array (
0 =>
array (
'formatted_address' => '10 Downing St, London SW1A 2AA, United Kingdom',
'geometry' =>
array (
'location' =>
array (
'lat' => 51.503363499999999,
'lng' => -0.12762480000000001,
),
'viewport' =>
array (
'northeast' =>
array (
'lat' => 51.503432400000001,
'lng' => -0.12551999999999999,
),
'southwest' =>
array (
'lat' => 51.503156800000014,
'lng' => -0.12832640000000001,
),
),
),
'icon' => 'https://maps.gstatic.com/mapfiles/place_api/icons/civic_building-71.png',
'id' => 'ffd85a3e543406e34703ee947c73ef54f5e167fe',
'name' => '10 Downing Street',
'photos' =>
array (
0 =>
array (
'height' => 2534,
'html_attributions' =>
array (
0 => 'Christopher Chan',
),
'photo_reference' => 'CoQBdwAAAHdqDNRUhalI7Ko_YXqckWM5M7I1IeD0xXOvjnxruS4BYCFnt99lCEy5xQJh7XtTvGTfZbKlnVhbxaJ_OloLxaPyoInqIpgRY-3LyB3Q70tDX3izeraFEM4Bw-ExmRzz6h18iMQlKb0DoDXnW26uO4RR-7YFjPNi6M0y5D7cmrl9EhAmI7GerM-TXpKD3BVVTtOWGhQZotS0ZNI2nK9G7jXxDEyvoQ5IxQ',
'width' => 3801,
),
),
'place_id' => 'ChIJRxzRQcUEdkgRGVaKyzmkgvg',
'rating' => 3.3999999999999999,
'reference' => 'CmRSAAAAh-Drhh9G_EW3azxZSikW_jR-ZjI2lhZTw6MfWqh9EiTaCEy4uW2okv_g6QfaKoupoeDu3DpfS6MjIvUvp6cc2uAoLlyH9NbkMrnQg9q3ED3R91OejmAScjRhe8G47kJ1EhD_oYVFakm4n6I27j-8iN6oGhQVH6rv1t6uGQBVVOqy1fCAB17JOg',
'types' =>
array (
0 => 'point_of_interest',
1 => 'establishment',
),
),
),
)),
'status' => 'OK',
),
))
I want to get the formatted_address element from the collection. it appears under the results element, that in turn has a collection under it with elements Items,0,formatted_address.
when i start trying to 'walk down' to the element i require I get index not found for Items
var_export($response['results']['items']);
so essentially, how am I supposed to interact with collections? i have tried google but most the links tell me about the extra functions that collections provide and not how to get data from it
any help greatly appreciated.
I think https://laravel.com/docs/5.3/collections#method-all explains what you are missing. You want to call
->all()
on your Collection to return the underlying array represented by the collection.
Than you can access fields in the returned array.

How to collect such info in magento listing page?

I need the catalog_product_entity_media_gallery table value data only on listing page.
When i am going to listing page and use the print_r($_productCollection);
$_productCollection on listing page returns me a array like this.
[_resourceName:protected] => catalog/product
[_resource:protected] =>
[_resourceCollectionName:protected] => catalog/product_collection
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[entity_id] => 160
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 104580
[has_options] => 0
[required_options] => 0
[created_at] => 2014-12-01 10:40:25
[updated_at] => 2014-12-01 11:51:15
[cat_index_position] => 1
[price] => 4.4900
[tax_class_id] => 4
[final_price] => 4.4900
[minimal_price] => 4.4900
[min_price] => 4.4900
[max_price] => 4.4900
[tier_price] =>
[name] => E Shisha E Liquid eKaiser *Menthol Flavour* 10ml Platinum Bottle Refill for Rechargeable E cigarette and E Shisha
[msrp_enabled] => 1
[msrp_display_actual_price_type] => 1
[thumbnail] => amazon_images/104580.jpg
[small_image] => amazon_images/104580.jpg
[image_label] =>
[small_image_label] =>
[thumbnail_label] =>
[url_key] => e-shisha-e-liquid-ekaiser-menthol-flavour-10ml-platinum-bottle-refill-for-rechargeable-e-cigarette-and-e-shisha
[short_description] => The eKaiser Platinum e Liquid range is made specifically for Cigarette smokers.
I need the only [small_image] value, which returns me only the amazon_images/104580.jpg
If any One have any idea, how to do it
Please help me.
Thank you
And also you can do like this :
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGallery('images') as $image) {
...
}
You can do like this on listing page.
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image) {
var_dump($image->getUrl());
}
A for loop in listing with getModel will slow down your listing page considerably.
With listing page you should only use flat tables for collection.
So you need to make sure that small image is populated in flat table.

How can I get the total number of documents found using the Nest?

I do the same request using the nest, and directly in ElastichSearch.
When I see direct request, how many documents match request.
"hits":
{
"total": 1640,
"max_score": 1,
"hits": [...]
}
My query:
var search = client.Search<RCompany>(s => s.Index("MyIndex")
.Query(qq => qq
.Filtered(m => m.Filter(f => f.Bool(b => b
.Must(
a => a.Term(z => z.Company.Code, param1),
a => a.Terms(z => z.Company.Id, param2),
a => a.Terms(z => z.Company.Field1.Id, param3)
)))
.Query(b => b.Bool(q => q.Should
(n => n.Match(a => a.OnField(d => d.Company.Field2).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field3).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field4).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field5).Query(param5).Operator(Operator.And))
)))))
.Size(10)
.SortDescending(n => n.DtCreate));
How can I find out how many documents suitable request using Nest?
There is a Total property on ISearchResponse which holds the total number of documents that matched the query. In your example, that would be search.Total.
The best way is to use the method Count as proposed by the official documentation
here the code
var result = client.Count<ElasticsearchProject>();

Iterating an array via Smarty in SugarCRM

When iterating an array in Smarty I am getting results conflicting with a print_r() of the same array.
When doing a print_r() on the array I can see that there are 2 objects in the array and each object is unique. However, when I run a print_r() on each item of the array (via foreach loop) I seem to get the same results for each item.
Can anyone identify what I'm doing wrong?
See the below code examples and results.
Code:
{$fields.rgggo_spreadsheetcellmap_documents.value->beans|#print_r}
Ouput:
Array
(
[a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => a852b076-a5cb-dda9-3868-52010d6957ab
[name] =>
[date_entered] => 08/06/2013 09:52am
[date_modified] => 08/06/2013 02:16pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] => Test 2
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => document_type_text_c
[row] => 3
[col] => 1
.... a bunch more stuff here
)
[f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
)
When I iterate the array...
{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
<pre>
{$v|#print_r}
</pre>
{{/foreach}}
I get these results:
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
I found the answer in another stackoverflow question. The issue is double vs single curly brackets and their use in SugarCRM.
Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?

Resources