在Windows下使用Curl工具完美操作ElasticSearch
来源:互联网 发布:罗斯福连任 知乎 编辑:程序博客网 时间:2024/06/05 07:27
首先可以从 http://curl.haxx.se/download.html上下载并安装Windows环境下的Curl。安装完成后,将Curl的I386目录的完整路径添加到Windows的Path环境变量中。
一番搜索后,终于发现Cygwin和Curl联手,可以完美解决这个问题。我们可以从http://cygwin.com/install.html上下载安装,然后进入CygWin命令行,键入:
返回结果如下所示:
然后即可执行下面的搜索语句,其中的搜索类型为multi_match,就是要匹配多个字段。
搜索结果如下:
请注意搜索关键词中含有foxes这个复数名词。虽然这两个搜索结果中都没有出现这个词,但我们在title.english子属性中定义的english分词器将foxes转换为词根fox,所以我们能够发现这两条记录。另外,由于第二条记录中含有not关键字,title属性中的standard分词器将发挥作用,所以第二条记录被提到第一条的前面。
C:\Users\Carl>curl -XGET http://localhost:9200/{ "name" : "node_01", "cluster_name" : "dfs", "version" : { "number" : "2.4.0", "build_hash" : "ce9f0c7394dee074091dd1bc4e9469251181fc55", "build_timestamp" : "2016-08-29T09:14:17Z", "build_snapshot" : false, "lucene_version" : "5.5.2" }, "tagline" : "You Know, for Search"}但是,Windows下的Curl不支持多行输入,搜索之后,http://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line上提供的方法也不灵。在Curl每行命令最后加上^符号,确实可以输入完成整个命令,但不能获得正常结果:
C:\Users\Carl>curl -XPUT http://localhost:9200/dept/employee/2?pretty -d '^More? {^More? "empname": "Carl Wu2"^{ "error" : { "root_cause" : [ { "type" : "mapper_parsing_exception", "reason" : "failed to parse" } ], "type" : "mapper_parsing_exception", "reason" : "failed to parse", "caused_by" : { "type" : "not_x_content_exception", "reason" : "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes" } }, "status" : 400}curl: (6) Could not resolve host: Carl Wu2^
一番搜索后,终于发现Cygwin和Curl联手,可以完美解决这个问题。我们可以从http://cygwin.com/install.html上下载安装,然后进入CygWin命令行,键入:
curl -XPUT http://localhost:9200/dept/employee/2?pretty -d '{"empname": "Carl Wu2"}'
返回结果如下所示:
再举个例子。我们可以使用下面的命令创建一个名叫my_index的索引,type名为blog,blog下面有一个属性叫title,该属性的分析器(Analyzer)为缺省的标准分词器(standard),title下面有个title.english的子属性,用的是english分词器。
curl -XPUT "http://localhost:9200/my_index" -d'{ "mappings": { "blog": { "properties": { "title": { "type": "string", "fields": { "english": { "type": "string", "analyzer": "english" } } } } } }}'
curl -XPUT "http://localhost:9200/my_index/blog/1" -d'{ "title": "I\"m happy for this fox" }'curl -XPUT "http://localhost:9200/my_index/blog/2" -d'{ "title": "I\"m not happy about my fox problem" }'
然后即可执行下面的搜索语句,其中的搜索类型为multi_match,就是要匹配多个字段。
curl -XGET http://localhost:9200/_search?pretty -d '{ "query": { "multi_match": { "type": "most_fields", "query": "not happy foxes", "fields": [ "title", "title.english" ] } }}'
搜索结果如下:
{ "took" : 15, "timed_out" : false, "_shards" : { "total" : 30, "successful" : 30, "failed" : 0 }, "hits" : { "total" : 2, "max_score" : 0.09362626, "hits" : [ { "_index" : "my_index", "_type" : "blog", "_id" : "2", "_score" : 0.09362626, "_source" : { "title" : "I\"m not happy about my fox problem" } }, { "_index" : "my_index", "_type" : "blog", "_id" : "1", "_score" : 0.0701148, "_source" : { "title" : "I\"m happy for this fox" } } ] }}
请注意搜索关键词中含有foxes这个复数名词。虽然这两个搜索结果中都没有出现这个词,但我们在title.english子属性中定义的english分词器将foxes转换为词根fox,所以我们能够发现这两条记录。另外,由于第二条记录中含有not关键字,title属性中的standard分词器将发挥作用,所以第二条记录被提到第一条的前面。
0 0
- 在Windows下使用Curl工具完美操作ElasticSearch
- windows下使用curl操纵ElasticSearch
- Windows下ElasticSearch的使用方式 CURL+Cygwin+Head插件
- 使用curl命令操作elasticsearch
- 使用curl命令操作elasticsearch
- 使用curl命令操作elasticsearch
- 使用curl命令操作elasticsearch
- 使用curl命令操作elasticsearch
- 在Windows下使用curl命令
- 在Windows下使用curl命令
- 在Windows下使用curl命令
- Windows下curl使用
- Windows下curl使用
- Windows下curl使用
- windows+curl+elasticsearch
- Elasticsearch笔记二之Curl工具基本操作
- Elasticsearch笔记二之Curl工具基本操作
- ElasticSearch之CURL操作
- 【并查集】并查集详解(转)
- 从零开始搭建maven+springmvc+mybatis web项目(1)---maven项目目录创建
- VC模拟鼠标的两种方式(SendMessage、mouse_event)
- Trapping Rain Water II
- 解决80端口被占用
- 在Windows下使用Curl工具完美操作ElasticSearch
- AndroidStudio项目提交(更新)到github最详细步骤
- 【Maven】mybatis-generator-maven-plugin 使用
- 校门外的树木
- Qt实现窗体在显示屏旁边自动隐藏(类似QQ)
- 在阿里云盘扩容过程中遇到的坑
- Socket Java设置超时时间
- 操作系统 进程管理之处理机调度
- HTTP 304 返回状态码的意思是什么