elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.07k stars 24.83k forks source link

Return highlighted fragment doesn't work #18389

Closed emaudoux closed 8 years ago

emaudoux commented 8 years ago

Elasticsearch version: 2.3.2 JVM version: 1.8.0_91 OS version: ubuntu 16.04 LTS

I want ES to return 150 characters of the highlighted parts of the field "recipe". Now there are no change (I think) between when I wrote the "highlight" lines and before:

(nb it is a Perl code but just replace the => by : and you have a typical ES request)

 my $range_cooktime_filter   = { "range" => { "cooktime" => { "lte" => $full_recherche{cooktime_max} } } };

  my $range_difficulty_filter = { "range" => { 
                                  "difficulty_int"  => { 
                                  "lte"   => $full_recherche{difficulty_max}, 
                                  "gte"  => $full_recherche{difficulty_min} } } };

  my $range_price_filter      = { "range"       => { 
                                  "price_int"   => { 
                                  "lte"  => $full_recherche{price_max}, 
                                  "gte"  => $full_recherche{price_min} } } };

  my $must_not   = { "multi_match" => {
                     "query"       => $full_recherche{ingredients_neg},
                     "fields"      => [ qw/title recipe ingredients/ ], } };

  my $multimatch = { "multi_match" => {
                     "query"       => $full_recherche{general},
                     "operator"    => "and",
                     "fields"      => [ qw/title recipe ingredients/ ], } };

  my $type_filter = {"term" => { "type" => $full_recherche{type} } };

  my $matchall = { "match_all" => {} };

  my $unfiltered      = ($full_recherche{general} eq "") ? $matchall : $multimatch;
  my $type_filterF    = ($full_recherche{type} == undef) ? $matchall : $type_filter;

  my $results = $e->search(
    "size" => 10,
    "from" => 0,
    "body" => {
      "query" => {
        "bool" => {
          "must" => $unfiltered,
          "filter" => [ $range_cooktime_filter, 
                        $range_difficulty_filter, 
                        $range_price_filter,
                        $type_filterF
                        ],
          "must_not" => $must_not,
        }
      },
      "highlight" => {
         "fields" => {
            "recipe" => {"fragment_size" => 150, "number_of_fragments" => 1}
          }
        }
      }
    }
  );

Thank you very much !

clintongormley commented 8 years ago

@emaudoux please upload a complete recreation in curl syntax. You haven't given us the index settings, the mappings, or the document. Btw, with the Perl client just do:

$e = Search::Elasticsearch->new(trace_to => 'Stdout')

and it will dump all your requests in curl syntax

clintongormley commented 8 years ago

Also, please make the recreation as small as possible - I don't want to have to wade through lots of fields etc that don't form a part of the problem

emaudoux commented 8 years ago

I'm not sure I understand everything you said above but still , here is my request :


    "size" : 10,
    "from" : 0,
    "body"  : {
      "query" :{
        "bool" : {
          "must" : {
            "multi_match" : { "query" : $full_recherche{general},
                                        "operator" : "and",
                     "fields" : [ qw/title recipe ingredients/ ], 
            } 
         },
          "filter" : [ ...  ],
          "must_not" : $must_not,
        }
      },
      "highlight" : {
         "fields" : {
            "recipe" : {}
          }
        }
      }
    }
  );`

Here is the mapping :

{
    "mappings": {
        "docs": {
            "properties": {
                ...
                "recipe": { "type": "string", "index": "analyzed", "analyzer": "french" },
                ...
            }
        }
    }
}
clintongormley commented 8 years ago

@emaudoux Unless you provide a full recreation that we can copy and paste which demonstrates the issue (without having to guess about what values you're passing in), nobody is likely to look at this.

here's an example of what a full recreation looks like: https://github.com/elastic/elasticsearch/issues/11277#issuecomment-105249937

emaudoux commented 8 years ago

I finally found the problem, it was a silly mistake, thank you for the time you spent on this. And sorry for the disturbance.