小编Siy*_*lav的帖子

请求包含无法识别的参数:[type] 在弹性搜索中,同时请求获取建议

我是 node js + express 中弹性搜索的新手,我正在努力在弹性搜索中获得建议。

下面的事情,我已经完成之前提出要求 es 建议。

1)我已经为索引创建了 es 索引(名称-“电影”)和类型(“电影”)和映射。

指数是:

return elasticClient.indices.create({
      index:"movies",
      body : {
        "settings" : {
          "index" : {
              "number_of_shards" : 5,
              "number_of_replicas" : 2
          }
        }
      }
    });
  }
Run Code Online (Sandbox Code Playgroud)

映射是:

createMovieMapping:function(){
    return elasticClient.indices.putMapping({
      index:"movies",
      type:"movie",
      body:{
          properties:{
            movieName : {type:"string"},
            suggest:{
              type:"completion",
              analyzer:"simple",
              search_analyzer:"simple",
              payloads:true
            }
          }
        }
    })
  }
Run Code Online (Sandbox Code Playgroud)

2)将一些数据从我的数据库推送到类型为“电影”的索引“电影”。

在索引中添加数据的函数:

addDataToMovieEsIndex:function(document){
    return elasticClient.index({
      index:"movies",
      type:"movie",
      id:document._id, // for preventing duplicate insertion
      body:{
        movieName:document.movie_name,
        suggest:{
          input : document.movie_name.split(" "),
          output : document.movie_name, …
Run Code Online (Sandbox Code Playgroud)

node.js express elasticsearch

5
推荐指数
1
解决办法
3370
查看次数

为什么我们使用 Golang 接口来模拟方法

我是 Golang 新手,一直在探索但不清楚单元测试中的模拟。谁能解释以下具体问题?

问题1:在Golang中编写单元测试时,为什么我们需要mock方法的接口,为什么不仅仅是struct?

问题2:为什么我们在结构体中注入接口(我们调用外部方法的地方)

与结构 -

type GlobalData struct {}

var (
    GlobalObj = GlobalData{}
)

func (g GlobalData) GetGlobalData(a string) string{
    return a
}
Run Code Online (Sandbox Code Playgroud)

有接口定义-

type GlobalInterface interface {
    GetGlobalData(a string) string
}

type GlobalData struct {}

var (
    GlobalObj = GlobalData{}
)

func (g GlobalData) GetGlobalData(a string) string{
    return a
}
Run Code Online (Sandbox Code Playgroud)

谢谢

struct unit-testing interface mocking go

4
推荐指数
1
解决办法
6690
查看次数

如何在 Spring Boot Rest api 响应的 ResponseEntity 中添加自定义属性

Spring Boot 提供了 ResponseEntity 来表示 REST API 的 HTTP 响应,包括 headers、body 和 status。

我的 RestController 包含 getTodoById 方法,如下所示-

@GetMapping("/todo/{id}")
 public Todo getTodoById(@PathVariable String id) {
        int todoId = Integer.parseInt(id);
        Todo todoItem = todoRepository.findById(todoId);
         ResponseEntity.ok(todoItem);
    }
Run Code Online (Sandbox Code Playgroud)

它在 api hit(api/v1/todo/13) 上给出以下 api 响应。

{
    "id": 13,
    "title": "title13",
    "status": "not started"
}
Run Code Online (Sandbox Code Playgroud)

应用程序中的所有 api 都需要有一个通用的自定义响应结构,如下所示:

{
  "status": "success",
  "data": {
    "id": 13,
    "title": "title13",
    "status": "not started"
  },
  "error": null,
  "statusCode": 200
}

{
  "status": "failure",
  "data": {},
  "error": "bad request",
  "statusCode": …
Run Code Online (Sandbox Code Playgroud)

java rest httpresponse spring-boot spring-restcontroller

3
推荐指数
1
解决办法
8002
查看次数

AttributeError:'module'对象在执行python函数timeit时没有属性'timeit'

我想计时python函数或想要打印执行my_function()12次迭代所需的最佳时间.下面是我的代码:

def my_function():
    print "hello"

if __name__ == "__main__":
    import timeit
    setup = "from __main__ import my_function"
    print timeit.timeit("my_function()", setup=setup,number=12)
Run Code Online (Sandbox Code Playgroud)

但我越来越错误了

Traceback (most recent call last):
  File "timeit.py", line 7, in <module>
    print timeit.timeit("my_function()", setup=setup,number=12)
AttributeError: 'module' object has no attribute 'timeit'
Run Code Online (Sandbox Code Playgroud)

任何人请帮助..

python timeit

0
推荐指数
1
解决办法
1132
查看次数