2016-12-23 109 views
0

我是Elastic 5.1的新手(通常是弹性的新手),我有一个使用msearch发送给弹性的列表。Elasticsearch没有匹配的msearch查询

但是以下不返回任何命中,但我的索引文件是这样的:

{ 
"_index": "all_items", 
"_type": "product", 
"_id": "1000002007900", 
"_version": 2, 
"found": true, 
"_source": { 
    "doc": { 
     "title": "title here", 
     "brand": null, 
     "updatedOn": "2016-12-22T14:00:26.016290", 
     "price": 49, 
     "viewed7": 0, 
     "idInShop": "11", 
     "active": true, 
     "model": null, 
     "_id": 1000002007900, 
     "purchased7": 0 
    }, 
    "doc_as_upsert": true 
} 

}

,这里是发送到msearch

[ 
{ 
    "index": "all_items", 
    "type": "product" 
}, 
{ 
    "sort": [ 
     { 
      "_score": "desc" 
     } 
    ], 
    "query": { 
     "function_score": { 
      "query": { 
       "bool": { 
        "filter": [ 
         { 
          "term": { 
           "active": true 
          } 
         } 
        ], 
        "should": [], 
        "must_not": [], 
        "must": [] 
       } 
      }, 
      "functions": [ 
       { 
        "script_score": { 
         "script": { 
          "lang": "painless", 
          "inline": "_score * params.constant * (doc['discountPrice'] > 0 ? doc['price']/doc['discountPrice'] : 0)", 
          "params": { 
           "constant": 1.2 
          } 
         } 
        } 
       } 
      ], 
      "score_mode": "multiply" 
     } 
    }, 
    "from": 0, 
    "size": 3 
} 

体]

如果我只发送{"query":{"match_all":{}}}我得到点击。

回答

0

你可以用match query来得到你想要的结果。

[ 
{ 
    "index": "all_items", 
    "type": "product" 
}, 
{ 
    "sort": [ 
     { 
      "_score": "desc" 
     } 
    ], 
    "query": { 
     "function_score": { 
      "query": { 
       "match": { 
        "active": true 
       } 
      }, 
      "functions": [ 
       { 
        "script_score": { 
         "script": { 
          "lang": "painless", 
          "inline": "_score * params.constant * (doc['discountPrice'] > 0 ? doc['price']/doc['discountPrice'] : 0)", 
          "params": { 
           "constant": 1.2 
          } 
         } 
        } 
       } 
      ], 
      "score_mode": "multiply" 
     } 
    }, 
    "from": 0, 
    "size": 3 
} 
] 

您可以在此link阅读更多关于match queryterm based query(你使用)。

相关问题