I'm using "query string query".
As you can see, my query combines field match (user:jack) and text (first).
As a result, elasticsearch will highlight the word jack in both user field and message.
But I query for user:jack, mean I want to highlight only user name jack and not jack in other fields.
I can't set require_field_match to true, because than elasticsearch will not highlight 'first'.
Unfortunately it wouldn't work
This will not highlight the word 'first' (like I wrote in the question:
I can't set require_field_match to true, because than elasticsearch will not highlight 'first').
Sure it will - but only if you explicitly search that field instead of the
_all field. Do query_string: {fields: "comment, message", query: "your
query"} and it should work. I've totally done it before but I have to admit
I haven't tested it this morning.
I don't understand why should I determine that I want highlight on text in the search level (and not at highlight section)?
Another question, let's say my document looks like this:
{
"type": "tweet",
"fields": {
"user" : "jack",
"message" : "I'm jack",
"comment" : "my first tweet"
}
}
Can I search on fields.* instead of specific fields, like: {fields: "comment, message", query: "your query"}?
I understand that on _all it's not working, but I see in elasticsearch documentation that I can use wildcard, they use the follow example:
{
"query_string" : {
"fields" : ["city.*"],
"query" : "this AND that OR thus",
"use_dis_max" : true
}
}
For me it failed with SearchPhaseExecutionException
Any suggestion?
This will raise a NumberFormatException.
I understand from elasticsearch doc on "Multi Field", that the idea of running the query_string query against multiple fields is to expand each query term to an OR clause like this:
field1:query_term OR field2:query_term | ...
In this example, times:first will failed, because times configured as long.
Is that mean that I can't highlight fields from type long (other than string)?
For the most part that is true, yes. Some of the highlighters make an effort to stringify the non-string data first and then do string highlighting against it but that is lame and haphazard. Its not something that's particularly well thought out frankly.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.