2017-02-03 125 views
0

您好我有在elasticsearch V2.3 凸顯一些問題確切查詢怪異的亮點我不能拿出與這裏的原因這個問題的任何邏輯是兩個例子:用或使用查詢字符串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 
} 

檢查查詢第二部分完全匹配或OR分開。我只是互換了第一和第二句話,這是第一位的結果,其中突出的文字這是錯誤的:

"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" 
    ] 
} 

},

,但第二個結果是好的:

"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 
      } 
     } 

我不知道這是否會奏效。讓我知道。