Elasticsearch query error in percolate query in ES - elasticsearch

I am use the percolate query in ES. But I don't merge bool query and sort query:
My purpose:
Sort prices of added product today.
My existing index
PUT /product-alert
{
"mappings": {
"doctype": {
"properties": {
"product_name": { "type": "text" },
"price": { "type": "double"},
"user_id": { "type": "integer" },
"date" : { "type": "date" }
}
},
"queries": {
"properties": {
"query": {
"type": "percolator"
}
}
}
}
}
I have a following error.
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "mapper [sort] of different type, current_type [text], merged_type [ObjectMapper]"
}
],
"type": "illegal_argument_exception",
"reason": "mapper [sort] of different type, current_type [text], merged_type [ObjectMapper]"
},
"status": 400
}
Elastic query:
PUT /product-alert/queries/1?refresh
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "(product_name:iphone)"
}
},
{
"range": {
"created_at": {
"gte": "2017-05-12",
"lte": "2017-05-12",
"include_lower": true,
"include_upper": true
}
}
}
]
}
},
"from": 0,
"size": 200,
"sort": [
{
"price": {
"order": "asc"
}
},
"_score"
]
}
Where is my fault? Sort working 'sort':'_score' only, but it is mischievous to me.
Thanks in advance

Related

elasticsearch with range sub query in nested query

I am trying to get a nested query filter inside of a nested.
here is my es mapping: there is one "id" field(long) and a nested field called "my_field" with four sub fields in it.
{
"my_index": {
"mappings": {
"dynamic": "strict",
"properties": {
"id": {
"type": "long"
},
"my_field": {
"type": "nested",
"properties": {
"x": {
"type": "long"
},
"y": {
"type": "long"
},
"z": {
"type": "long"
},
"a": {
"type": "double"
},
"b": {
"type": "long"
}
}
}
}
}
}
}
My question is how to retrive the document with nested es query which contains sub range query in it.
For example, I'm trying to get two document id :11111 and id:22222 with nested query restriction "x > 15" or "a > 0.5" and also with inner hit size limitation, which is 20 here.
{
"_source": false,
"query": {
"bool": {
"must": {
"nested": {
"inner_hits": {
"size": 20
},
"path": "my_field",
"query": {
"bool": {
"should": [
{
"range": {
"x": {
"from": 15,
"include_lower": true,
"include_upper": true,
"to": null
}
}
},
{
"range": {
"a": {
"from": 0.5,
"include_lower": true,
"include_upper": true,
"to": null
}
}
}
]
}
}
}
},
"should": [
{
"term": {
"id": 11111
}
},
{
"term": {
"id": 22222
}
}
]
}
},
"timeout": "5000ms",
"track_total_hits": true
}
However, there are no hits return
Please use the dot notation in your query to include the complete path, e.g.,
"range": {
"my_field.x": { "from": ... }
}

Elasticsearch index_out_of_bounds exception for multi level nested and reverse_nested aggregation

I have an elasticsearch index with multiple deep level nestings. I am performing terms aggregation on one deep level field and want to fetch all the records for another associated deep level field. For which I am using the top_hits aggregation. But my query is returning me "index_out_of_bounds" exception.
Here are index mappings:
{
"mappings": {
"type": {
"properties": {
"campaigns": {
"type": "nested",
"properties": {
"campaign_id": {
"type": "integer"
},
"campaign_name": {
"type": "text"
},
"contents": {
"type": "nested",
"properties": {
"content_id": {
"type": "integer"
},
"content_name": {
"type": "text",
"fielddata": true
}
}
}
}
},
"forms": {
"type": "nested",
"properties": {
"form_id": {
"type": "integer"
},
"form_issubmitted": {
"type": "integer"
},
"form_name": {
"type": "text"
},
"form_tabs": {
"type": "nested",
"properties": {
"tab_id": {
"type": "integer"
},
"tab_name": {
"type": "text"
},
"tab_section": {
"properties": {
"section_id": {
"type": "long"
},
"section_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
}
}
}
and my query is looking like this:
{
"size": 0,
"aggs": {
"sectionAgg": {
"nested": {
"path": "forms.form_tabs.tab_sections"
},
"aggs": {
"termsField": {
"filter": {
"bool": {}
},
"aggs": {
"sectionFields": {
"terms": {
"field": "forms.form_tabs.tab_sections.section_id",
"size": 10000
},
"aggs": {
"sectionFieldDocs": {
"top_hits": {
"size": 1,
"_source": [
"forms.form_tabs.tab_sections.*"
]
}
},
"completioncampaigns.contentsFields": {
"reverse_nested": {
"path": "campaigns.contents"
},
"aggs": {
"completionFieldFilter": {
"filter": {
"bool": {}
},
"aggs": {
"campaignContents": {
"top_hits": {
"size": 100,
"_source": [
"campaigns.contents.*"
]
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Not pasting the whole result otherwise, it'll be very long. But it does have aggregation data also.
And it is throwing me the error like this
{
"took": 178,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 2,
"skipped": 0,
"failed": 3,
"failures": [
{
"shard": 1,
"index": "userlocal",
"node": "KmxVF34iTXWeLFLmtCy7WQ",
"reason": {
"type": "index_out_of_bounds_exception",
"reason": "2147483647 is out of bounds: [0-803["
}
},
{
"shard": 2,
"index": "userlocal",
"node": "KmxVF34iTXWeLFLmtCy7WQ",
"reason": {
"type": "index_out_of_bounds_exception",
"reason": "2147483647 is out of bounds: [0-1278["
}
},
{
"shard": 4,
"index": "userlocal",
"node": "KmxVF34iTXWeLFLmtCy7WQ",
"reason": {
"type": "index_out_of_bounds_exception",
"reason": "2147483647 is out of bounds: [0-2659["
}
}
]
}
}
I want to know why this error is happening and how to resolve this.

ElasticSearch - How to sort by "date_range"

Is it possible to sort by "date_range" field in Elasticsearch?
If yes, how?
My Elasticsearch version: 6.3.0
You can find my examples below.
I want to sort by "dater"
Thanks,
Mapping:
PUT testindex
{
"mappings": {
"datetest": {
"properties": {
"created": {
"type": "date"
},
"id": {
"type": "keyword"
},
"Name": {
"type": "keyword"
},
"dater": {
"type": "date_range"
}
}
}
}
}
query:
GET /testindex/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"dater": {
"order": "desc"
}
}
]
}
result:
error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is not supported on field [dater] of type [date_range]"
}
]
}

ElasticSearch query doesn't return documents that have an "empty" nested property

I'm running into a weird problem. I have a document mapping for which one of the properties is a nested object.
{
"userLog": {
"properties": {
"userInfo": {
"userId": {
"type": "text"
},
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
},
"email": {
"type": "text"
}
},
"violations": {
"type": "integer"
},
"malfunctions": {
"type": "integer"
},
"extensionsUsed": {
"type": "integer"
},
"date": {
"type": "date",
"format": "yyyy-MM-dd||yyyy/MM/dd||yyyyMMdd||epoch_millis"
},
"events": {
"type": "nested",
"properties": {
"editorId": {
"type": "text"
},
"editorRole": {
"type": "text"
},
"editedTimestamp": {
"type": "date",
"format": "epoch_millis"
},
"createdTimestamp": {
"type": "date",
"format": "epoch_millis"
},
"userId": {
"type": "text"
},
"timestamp": {
"type": "date",
"format": "epoch_millis"
},
"eventType": {
"type": "text"
}
}
}
}
}
}
Some userLogs have events and some don't. My queries only return userLogs that have events, however, and I'm not sure why. There are definitely userLogs that exist without events in the index. I can see them in Kibana. They just aren't returned in the search. Here's what I'm running for a query:
GET index_name/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"date": {
"gte": "20170913",
"format": "yyyyMMdd"
}
}
}
],
"should": [
{
"match_phrase": {
"userInfo.userId": "Xvo9qblajOVaM3bQQMaV4GKk7S42"
}
}
],
"minimum_number_should_match": 1
}
}
}
based on this discussion
I modified my query to be the following:
GET one20_eld_portal/_search
{
"query": {
"bool": {
"must_not": [
{
"nested": {
"path": "events",
"query": {
"bool": {
"filter": {
"exists": {
"field": "events.userId"
}
}
}
}
}
}
],
"should": [
{
"match_phrase": {
"userInfo.uid": "Xvo9qblajOVaM3bQQMaV4GKk7S42"
}
}
],
"minimum_should_match": 1
}
}
}
but this doesn't return any results. Any help is greatly appreciated!
Turns out the reason the "empty" logs weren't being returned is because the userId wasn't being set properly for empty logs.

Using inner_hits inside an aggregation

I have a collection of documents which all contain an array of nested objects with important data. I want do to an aggregation on these which returns me the first document, last document, and all of the nested objects in that group. I can achieve everything in that list except for the nested objects.
Mapping:
"instances": {
"properties": {
"aggField": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "integer"
},
"nestedObjs": {
"type": "nested",
"properties": {
"key": {
"type": "string",
"index": "not_analyzed"
},
"value": {
"type": "integer"
}
}
},
"timestamp": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
Query:
{
"size" : 0,
"aggs" : {
"agg-buckets" : {
"terms" : {
"field" : "aggField",
"size" : 10
},
"aggs": {
"last-report": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"size": 1
}
},
"first-report": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "asc"
}
}
],
"size": 1
}
},
"nested-objs": {
"nested": {
"path": "nestedObjs",
"inner_hits": {}
}
}
}
}
}
But this fails with:
Parse Failure [Unexpected token START_OBJECT in [nested-objs].]
If I remove the "inner_hits" field it works ok. But it just gives me the document count and not the documents themselves.
What am I doing wrong?
E: I'm using ES version 1.7.1
Are you sure that inner_hits is allowed in a nested aggregation (as opposed to a nested query)? I suspect that's what's causing the error.

Resources