elasticsearch,Node.js,elasticsearch" /> elasticsearch,Node.js,elasticsearch" />

Node.js 如果查询属于特定类型的字段,则编写一个查询以提升结果

Node.js 如果查询属于特定类型的字段,则编写一个查询以提升结果,node.js,elasticsearch,Node.js,elasticsearch,我现在在Node.js中使用Elasticsearch。我遇到的问题是,我想写一个查询,如果它属于某个特定类型的字段,我想提高我的结果,例如,如果我有索引:商人和类型:餐厅、时尚这两种类型都有字段商店名称,现在我想我的搜索结果得到提高到2倍,如果商店的名称是在餐厅类型,而不是时尚 下面是我写的问题 index: 'merchants', type: ['fashion', 'restaurant'], body: { "query":{ bool: {

我现在在Node.js中使用Elasticsearch。我遇到的问题是,我想写一个查询,如果它属于某个特定类型的字段,我想提高我的结果,例如,如果我有索引:商人类型:餐厅、时尚这两种类型都有字段商店名称,现在我想我的搜索结果得到提高到2倍,如果商店的名称是在餐厅类型,而不是时尚

下面是我写的问题

  index: 'merchants',
  type: ['fashion', 'restaurant'],
  body: {
     "query":{
        bool: {
          "disable_coord": true,
          should: [
          {
            "constant_score": {
              boost: 1.00, // HERE BOOST IS 1 as field is in type FASHION
              "query": {
                "wildcard" : { "fashion.shop_name" : last_wildcard_string }
              }
            }
          },
          {
            "constant_score": {
              boost: 2.00, // HERE BOOST IS 2 as field is in type RESTAURANT
              "query": {
                "wildcard" : { "restaurant.shop_name" : last_wildcard_string }
              }
            }
          }
          ], "minimum_should_match": 1
       }
     }
  }
现在我不知道为什么,但在我猜之前2-3个月,上面的代码运行良好,但现在我不知道为什么上面的代码没有返回任何东西

有人能告诉我我做错了什么,因为在它工作正常之前。否则,请告诉我,这不是写fashion.shop\u name定义fashion类型的shop\u name的正确方法吗

无论如何,谢谢。

试试这个

{
"query" : {
    "bool" : {
        "should" : [{
                "bool" : {
                    "must" : [{
                            "wildcard" : {
                                "shop_name" : {
                                    "value" : "last_wildcard_string",
                                    "boost" : 2.0
                                }
                            }
                        }, {
                            "term" : {
                                "_type" : "restaurant"
                            }
                        }
                    ]
                }
            }, {
                "bool" : {
                    "must" : [{
                            "wildcard" : {
                                "shop_name" : {
                                    "value" : "last_wildcard_string",
                                    "boost" : 1.0
                                }
                            }
                        }, {
                            "term" : {
                                "_type" : "fashion"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

}

什么版本的elasticsearch?您是否升级了elasticsearch或nodejs api?