Elasticsearch Highlight - elasticsearch

I have a Elasticsearch 2.4.0 installation. Now I would like to use highlight information. With the following query I get a result list with some hits, but no highlights. Any idea?
Regards CL
{
"query": {
"query_string" : {
"query": "harley"
}
},
"highlight" : {
"pre_tags" : ["<tag1>"],
"post_tags" : ["</tag1>"],
"fields" : {
"GivenName" : {},
"FamilyName" : {}
}
}
}

Related

query object from ES

I have below ES mapping
"students" : {
"properties" : {
"tag" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "keyword"
},
"name" : {
"type" : "text"
}
}
},
how do I query from students->tag->id since students is not defined as nested.
I need a query which can support more than one id to match
Simply like this:
{
"query": {
"nested": {
"path": "students.tag",
"query": {
"term": {
"students.tag.id": "1234"
}
}
}
}
}

Multilevel Nested Query - RequestError Exception 400 - Failed to create query

I am using Elasticsearch 5.1.1. While doing a nested query, it is returning 400 Error
My Doc will look like this
{
"_index" : "test",
"_type" : "test_five",
"_source" : {
"doc" : {
"keyword_elas" : "elasticsearch",
}
},
"doc_as_upsert" : true }
This is my Query Code
{
"query": {
"nested": {
"path":"_source",
"query": {
"nested": {
"path": "_source.doc",
"query": {
"match": {
"_source.doc.keyword_elas": "elasticsearch"
}
}
}
}
}
}}
For the above Query i got an exception
elasticsearch.exceptions.RequestError: TransportError(400,
u'search_phase_execution_exception', u'failed to create query: {\n
"nested" : {\n "query" : {\n "nested" : {\n
Is this an exception due to some Query Mistake ? or any Version problem...
Thank You
I am not quite sure why you're using a nested query in this environment.
If I have a document like this :
{
"_index" : "test",
"_type" : "test_five",
"_source" : {
"doc" : {
"keyword_elas" : "elasticsearch",
}
},
"doc_as_upsert" : true }
And my goal is to match the keyword_elas field. All I would do is :
GET test/test_five/_search
{
"query": {
"match" : {
"keyword_elas" : "elasticsearch"
}
}
}
Exact Matches :
Analyzed field :
GET test/test_five/_search
{
"query": {
"match" : {
"keyword_elas" : "elasticsearch",
"fuzziness": "0"
}
}
}
Note : If you have a document in keyword_elas that contains elasticsearch ABC , this query will work because it will be zero fuzziness on the first token (elasticsearch).
For not analyzed fields (fully exact match)
GET test/test_five/_search
{
"query": {
"term" : { "keyword_elas" : "elasticsearch" }
}
}
If you have two documents in your index with
keyword_elas : elasticsearch
and
keyword_elas : elasticsearch abc
The term query will only match the first document.

elasticsearch query on all array elements

How can I search for documents that have all of the specified tags in the following query? I tried minimum_should_match and "execution": "and", but none of them is supported in my query.
GET products/fashion/_search
{
"query": {
"constant_score": {
"filter" : {
"bool" : {
"must" : [
{"terms" : {
"tags" : ["gucci", "dresses"]
}},
{"range" : {
"price.value" : {
"gte" : 100,
"lt" : 1000
}
}}
]
}
}
}
},
"sort": { "date": { "order": "desc" }}
}
====== UPDATE
I found a way to build my queries. The task was to reproduce the following mongodb query in the elasticsearch:
{
"tags": {
"$all":["gucci","dresses"]
},
"price.value":{"$gte":100,"$lte":1000}
}
And here is my elasticsearch query
GET products/fashion/_search
{
"query": {
"bool" : {
"filter" : [
{"term" : {
"tags" : "gucci"
}},
{"term" : {
"tags" : "dresses"
}},
{"range" : {
"price.value" : {
"gte" : 100,
"lt" : 1000
}
}}
]
}
}
}
Do you have a mapping defined for your index? By default, Elasticsearch will analyze string fields. If you want to find exact terms like you are above, you need to specify them as not_analyzed in the mapping.
https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_filter_with_text

How to search string over multiple fields in elastic search

I have to search "oil" over fields "BrandName","Desc" &"cat"
And in BrandName filed I have data "lucasoil product" data as oil is present in this I want this also to be get hit
I am using
{
"bool" : {
"must" : {
"query_string" : {
"query" : "oil",
"fields" : [ "BrandName", "Cat","Desc" ],
"default_operator" : "and"
}
}
}
But this not giving me the exact results, how to sort this out
Try this query
{
"query" :{
"bool" : {
"must" : {
"query_string" : {
"query" : "oil",
"fields" : [ "input", "output"],
"default_operator" : "and"
}
}
}
}
}
Check your mapping also once. It will look like this
{
"test":
{
"properties":
{
"BrandName":
{
"type": "string"
},
"Cat":
{
"type": "string"
},
"Desc":
{
"type": "string"
}
}
}
}

Elasticsearch: [filtered] query does not support [highlight]

I am new to Elasticsearch. I have a filtered query as follows
{
"query": {
"filtered" : {
"query" : {
"term" : {
"title" : "crime"
}
},
"highlight" : {
"fields" : {
"title" : {}
}
},
"filter" : {
"term" : { "year" : 1961 }
}
}
}
}
When I tried this query and got the error:
[filtered] query does not support [highlight]
Does filtered query support highlight? If not, how can I achieve highlight in query with filters? I have to use filters.
Thanks and regards!
The "highlight" parameter should go at the same level as the "query" parameter, not embedded within it. In your case it should look something like this:
{
"query": {
"filtered" : {
"query" : {
"term" : {
"title" : "crime"
}
},
"filter" : {
"term" : { "year" : 1961 }
}
}
},
"highlight" : {
"fields" : {
"title" : {}
}
}
}
Highlighting reference
Highlights problems with a filtered query

Resources