I am trying to create this grid and chart using KendoUi.
SalesOverrides
This is what I have so far. My question is how can I aggregate the cells of Data - Orders(lbs) for All - CustomerType with each CustomerType value, so that when one is changed the other one would be reflected?
Thanks,
Jordan Michael
All you need to do is specify the pertinent aggregate function name via the columns->aggregates. Here is a sample:
group: {
field: "CustomerType", aggregates: [
{ field: "May18", aggregate: "sum" },
{ field: "May18", aggregate: "sum" },
{ field: "Jun18", aggregate: "sum" },
{ field: "Jul18", aggregate: "sum" },
// ...
]
},
Check also the templates for the footer results documentation: https://demos.telerik.com/kendo-ui/grid/aggregates
Related
Documents
{'name': 'name whatever'}, {'name': 'foo whatever'}, ...
Search index
{
"mappings": {
"dynamic": false,
"fields": {
"name": [
{
"type": "string"
},
{
"maxGrams": 100,
"type": "autocomplete"
}
]
}
},
"storedSource": true
}
I want to search by what, whatever, name whatever
It seems ok when I searching what and whatever
// for what
{
index: 'indexName',
autocomplete: {
query: 'whatever',
path: 'name'
}
}
// for whatever
{
index: 'indexName',
autocomplete: {
query: 'whatever',
path: 'name'
}
}
But searching name whatever is not working what I expected,
{
index: 'indexName',
autocomplete: {
query: 'name whatever',
path: 'name'
}
}
this returns name whatever but also foo whatever
How can I get only name whatever?
I had a similar issue and I believe the answer was to include 'tokenOrder: sequential' in the search - so your query would look like this:
{
index: 'indexName',
autocomplete: {
query: 'name whatever',
path: 'name',
tokenOrder: 'sequential'
}
}
https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#token-order-example
The description for using sequential tokenOrder states:
sequential
Indicates tokens in the query must appear adjacent to each other or in the order specified in the query in the documents. Results contain only documents where the tokens appear sequentially.
I'm building a search engine for my audio store.
I only use 1 index for the audio documents and here is the structure:
{
id: { type: 'integer' },
title: { type: 'search_as_you_type' },
description: { type: 'text' },
createdAt: { type: 'date' },
updatedAt: { type: 'date' },
datePublished: { type: 'date' },
duration: { type: 'float' },
categories: {
type: 'nested',
properties: {
id: { type: 'integer' },
name: { type: 'text' }
},
}
}
It's simple to search by text the audio documents with the order by date published.
But I want to make it more powerful to make a text search and order by trending based on the audio listen times and purchase histories in a specific range, eg: text search trending audios for the last 3 months or the last 30 days, so I tweaked the structure as below:
{
...previousProperties,
listenTimes: {
type: 'nested',
properties: {
timestamp: { type: 'date' },
progress: { type: 'float' }, // value 0-1.
},
},
purchaseHistories: {
type: 'nested',
properties: {
timestamp: { type: 'date' }
},
},
}
And here is my query to get trending audios for the last 3 months and it worked:
{
bool: {
should: [
{
nested: {
path: 'listenTimes',
query: {
function_score: {
query: {
range: {
'listenTimes.timestamp': {
gte: $range,
},
},
},
functions: [
{
field_value_factor: {
field: 'listenTimes.progress',
missing: 0,
},
},
],
boost_mode: 'replace',
},
},
score_mode: 'sum',
},
},
{
nested: {
path: 'purchaseHistories',
query: {
function_score: {
query: {
range: {
'purchaseHistories.timestamp': {
gte: 'now+1d-3M/d',
},
},
},
boost: 1.5,
},
},
score_mode: 'sum',
},
},
],
},
}
I have some uncertainty with my approach such as:
The number of listen times and purchase histories record of each audio are quite big, is it effective if I structured the data like this? I just only test with the sample data and it seems to work fine.
Does Elasticsearch will re-index the whole document every time I push new records of listen times and purchase histories into the audio docs?
I'm very new to Elasticsearch, so could someone please give me some advice on this case, thank you so much!
First question is a good one, it depends how you will implement it, you will have to look out for atomic action since, I'm guessing, you're planning to fetch number of listen times and then save incremented value. If you're doing this from one application in one thread and it's managing to process it in time, then you're fine, but you're not able to scale. I would say that elasticsearch is not really made for this kind of transactions. First idea that popped into my brain is saving numbers into SQL database and updating elasticsearch on some schedule. I suppose those results don't have to be updated in real time?
And about second question I'll just post quote from elasticsearch documentation The document must still be reindexed, but using update removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation., you can find more on this link.
I have been stuck for 2 days on this and I am sure it can be done with Elasticsearch. Any help would be really appreciated!
I receive products from various sources and I want to integrate them to my current inventory.
Products reach me in the form of text. They generally have a brand and a name:
1000 Stories Zinfandel Bourbon Barrel Aged
1000 Stories Gold Rush Red Blend Bourbon Barrel
1000 Stories Cabernet Bourbon Barrel Aged
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Brand Product Name
But one can be missing or they can be mixed. That's why I want to recognize what is there and what is missing.
I generally already know the brands and products from my inventory. How can I get Elasticsearch to tell me which is what?
Ideally, I would get something like:
<brand>1000 Stories</brand> <name>Zinfandel Bourbon Barrel Aged</name>
<brand>1000 Stories</brand> <name>Gold Rush Red Blend Bourbon Barrel</name>
<brand>1000 Stories</brand> <name>Cabernet Bourbon Barrel Aged</name>
Though just recognizing the brand would already be a big step.
I was hoping to make it work with phrase suggestion, because it already includes the matches in the results. I have tried to map my brands and names with all those analyzers:
settings: {
analysis: {
analyzer: {
trigram: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase","shingle"]
},
reverse: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase","reverse"]
},
raw_analyzer: {
tokenizer: "keyword",
filter: [
"lowercase",
"asciifolding"
]
}
},
filter: {
shingle: {
type: "shingle",
min_shingle_size: 2,
max_shingle_size: 3
}
}
}
},
mappings: {
product: {
properties: {
brand: {
type: "text",
fields: {
trigram: {
type: "text",
analyzer: "trigram"
},
reverse: {
type: "text",
analyzer: "reverse"
},
raw: {
type: "text",
analyzer: "raw_analyzer"
}
}
}
And searched them with each analyzer:
phrase_name_suggestion: {
phrase: {
field: 'name.trigram',
max_errors: 0.99,
size: 5,
gram_size: 3,
direct_generator: [
{
field: "name.trigram",
suggest_mode: "always"
},
{
field: "name.reverse",
suggest_mode: "always",
pre_filter: "reverse",
post_filter: "reverse"
} ],
highlight: {
pre_tag: "<name>",
post_tag: "</name>"
}
}
},
phrase_name_raw_suggestion: {
phrase: {
field: 'name.raw',
max_errors: 0.99,
size: 5,
gram_size: 3,
highlight: {
pre_tag: "<name>",
post_tag: "</name>"
}
}
}
I am only getting random suggestions on the wrong terms, or no results at all. Like a term of a brand suggested for a term of a name, instead of just recognizing the brand.
Note in case it narrows the options: names are manually input, so I can get all variety of text: missing name, typos ("Sinfandel" for "Zinfandel"), abbreviations ("cab sauv" for "cabernet sauvignon"), ... That's a separate issue but if it can be included into this solution I'll happily take it.
I am running Elasticsearch 6.4.2. I can work with a more recent version if needed.
Currently i am working with ElasticSearch for indexing and querying of several million documents. Now i want to incorporate tags into these documents as well. And i am not quite sure, what the best way will be, to match my requirements, which are:
I want to query ES for most used tags. Paginating and filtering should be possible as well.
Is this even possible? I've tried using aggregations before and it kind of worked, but i was not able to paginate or filter the results.
{
size: 0,
aggs: {
group_by_tags: {
terms: {
field: "tags"
}
}
}
}
So, i thought using Nested Objects will be the way to go and i've changed the mapping, which now looks like this:
mappings: {
shop_outfits: {
_all: {
enabled: false
},
properties: {
id: {
type: "string",
index: "not_analyzed"
},
userId: {
type: "string",
index: "not_analyzed"
},
title: {
type: "string"
},
description: {
type: "string"
},
tags: {
type: "nested",
properties: {
tag: {
type: "string",
index: "not_analyzed"
}
}
},
articles: {
type: "string",
index: "not_analyzed"
},
uniqueId: {
type: "string",
index: "not_analyzed"
},
createdAt: {
type: "date",
format: "yyyy-MM-dd HH:mm:ss"
}
}
}
}
Is it possible to return all tags ordered by usage in a list that can be paginated? Or is this simply not possible with Nested Objects?
I am glad for any hint in the right direction!
EDIT:
Or is using a parent/child relationship the right way?
I'm new to ElasticSearch, so I need some help with it.
I have a query to search for products which can belong to many categories. Categories are combined in a nested tree.
Example data:
categories: [
{
id: 1,
name: 'First category',
categories:[
{
id: 12,
name: 'First subcategory'
},
{
id: 13,
name: 'Second subcategory'
}
]
},
{
id: 2,
name: 'Second category'
}
],
products: [
{
id: 1,
name: 'First product',
categories_ids: [2, 12]
},
{
id: 2,
name: 'Second product',
categories_ids: [1]
}
]
Besides the search results I need to get the categories tree including the number of search results in each category (excluding categories without any search results).
For the above example it should be:
First category (2)
First subcategory (1)
Second category (1)
Can someone explain how to do this using ElasticSearch's aggregations?
Thanks.
I had similar need and used Nested objects. Here is that thread
How to narrow down the current aggregation context to a specific scope within set of documents returned from Filter Aggregation?
I think you are in search for something around this:
{
"aggs": {
"category_agg": {
"terms": {
"field": "category_name"
},
"aggs": {
"sub_category_agg": {
"terms": {
"field": "sub_category"
},
"filter": {
"term": {
"sub_category": "First subcategory"
}
}
}
}
}
}
}
Apply filters (or omit) as on need and be sure the fields on which you make aggregations (category_name and subcategory_name in this example) to be not_analyzed.