2017-02-03 11 views
0

にクエリ文字列を使用してこんにちは、私はelasticsearch v2.3の 中のハイライトといくつかの問題があり、2つの例です:奇妙な正確なクエリのためのハイライトとOR elasticsearch

この

GET reports_all/all/_search 
{ 
    "query": { 
     "query_string": { 
     "fields": [ 
      "text" 
     ], 
     "query": "(\"base of the pyramid impact assessment\" OR \"corporate human rights benchmark\")" 
//  "query": "(\"corporate human rights benchmark\" OR \"base of the pyramid impact assessment\")" 
     } 
    }, 
    "highlight": { 
     "pre_tags": [ 
     "<mark>" 
     ], 
     "post_tags": [ 
     "</mark>" 
     ], 
     "fields": { 
     "text": { 
      "number_of_fragments": 10 
     } 
     } 
    }, 
    "size": 10, 
    "from": 0 
} 

照会部分を2つの完全一致またはORで区切ります。私はちょうど第一及び第二のフレーズを交換し、これは間違っているテキストで強調して最初の1の結果である:

"highlight": { 
    "text": [ 
    " organisations to launch <mark>the</mark> \n<mark>Corporate</mark> <mark>Human</mark> <mark>Rights</mark> <mark>Benchmark</mark> (CHRB), <mark>the</mark> \nworld’s first wide-scale project to", 
    " taking \naction to reduce <mark>the</mark> environmental \n<mark>impact</mark> <mark>of</mark> our business and finding \nnew ways to help", 
    " focuses <mark>of</mark> this is reducing <mark>the</mark> <mark>impact</mark> <mark>of</mark> \nclimate change. Aviva Investors signed <mark>the</mark> Montreal Carbon", 
    " \nprogrammes in 2015\n</p>\n<p>Our 2015 reporting\nThis is <mark>the</mark> summary <mark>of</mark> our sustainable\nbusiness and corporate", 
    " aim to uphold <mark>the</mark> highest ethical \nstandards in <mark>the</mark> way that we do business. \nIn 2015, 98% <mark>of</mark> Aviva", 
    " costs to \nour customers\n</p>\n<p> Reducing our\nenvironmental <mark>impact</mark>\nIn 2015 Aviva became <mark>the</mark>", 
    " first insurer \nto achieve <mark>the</mark> Carbon Trust Supply Chain \nStandard, in recognition <mark>of</mark> work to measure", 
    " Stonewall’s \nTop 100 Employers list\n</p>\n<p>A principal partner \n<mark>of</mark> <mark>the</mark> Living Wage \nFoundation", 
    " take control <mark>of</mark> their finances, as\nwell as benefiting society and <mark>the</mark> environment\n</p>\n<p>• <mark>The</mark> way", 
    " we help our local communities, giving\nthousands <mark>of</mark> organisations <mark>the</mark> support they need\nto make a" 
    ] 
} 

}、

が、第2 1の結果は罰金です:

"highlight": { 
     "text": [ 
     " organisations to launch the \n<mark>Corporate</mark> <mark>Human</mark> <mark>Rights</mark> <mark>Benchmark</mark> (CHRB), the \nworld’s first wide-scale project to" 
     ] 
    } 

が悪かったのかもしれないものの任意のアイデア?

答えて

0

は、私は何が起こっているのか非常にわかりませんが、あなたのクエリが暗黙的に追加されるがESアナライザにより、ANDクエリ内の別々の単語に分解されているように見えます。個別に各単語のためのハイライト<mark>を取得するための理由である

。あなたはESは単一のエンティティとしてbase of the pyramid impact assessmentを検討したい場合

あなたはmatch_phraseクエリを使用することができます。

クエリが

"query": { 
    "bool": { 
     "should": [ 
     { 
      "match_phrase": { 
       "text": "base of the pyramid impact assessment" 
      }}, 
      { 
       "match_phrase": { 
        "text": "corporate human rights benchmark" 
       } 
      } 
       ], 
       "minimum_number_should_match": 1 
      } 
     } 

ようになりますこれが機能するかどうかわかりません。お知らせ下さい。

関連する問題