对弹性搜索查询感到困惑 [英] Confused about elasticsearch query

查看:89
本文介绍了对弹性搜索查询感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  POST http:// localhost:9200 / test2 / drug?pretty 
{
title:我可以这样做
}


get test2 / drug / _search
{
query:{
match:{
title癌症
}
}
}

映射是:

  {
test2:{
mappings:{
drug :{
properties:{
title:{
type:string
}
}
}
}
}
}

运行上述查询返回文档。我想了解幕后做什么弹性?从默认分析器的输出看,它不会将癌症标记为can,所以为什么会返回一个带有can这个单词的文件,这是什么原因导致了这个返回?换句话说,搜索查询癌症发生了什么其他处理。



更新



是否有一个命令我可以在我的框上运行,这将清除所有的索引和所有的东西,所以我有一个干净的板岩?我运行delete / *成功但仍然得到匹配。

解决方案

您的测试问题是,如果您使用Sense ,获取请求。在感觉中应该是 GET (大写字母)。



解释与 GET POST http方法。
幕后感觉实际上将 GET 请求转换为 HTTP POST (给定许多浏览器不支持具有请求体的HTTP GET请求) 。这意味着,即使你写了 GET ,实际的http请求是一个 POST



由于Sense具有强制大写字母用于请求方法的自动完成,因此在决定是否为 GET 时使用相同的大写字母而不是小写获取)请求与请求体。如果是,则将该请求转换为 POST 一个。如果它比较请求方法并且决定不是一个GET,它按照原样发送请求,这意味着使用 get 方法和一个正文。由于身体被忽略,Elasticsearch到底会是一个 test2 / drug / _search ,它基本上是一个 match_all 。 / p>

        POST http://localhost:9200/test2/drug?pretty
        {
          "title": "I can do this"
        }


        get test2/drug/_search
        {
          "query" : {
            "match": {
              "title": "cancer"
            }
          }
        }

The mappings are:

        {
           "test2": {
              "mappings": {
                 "drug": {
                    "properties": {
                       "title": {
                          "type": "string"
                       }
                    }
                 }
              }
           }
        }

Running the above query returns the document. I want to understand what elastic is doing behind the scenes? From looking at the output of the default analyzer it does not tokenize cancer such that it returns "can" so why is a document with the word "can" being returned and what is causing this to be returned? In other words, what other processing is happening to the search query "cancer".

Updated

Is there a command I can run on my box that will clear all indexes and everything so I have a clean slate? I ran delete /* which succeeded but still getting a match.

解决方案

The problem with your test is, if you are using Sense, the get request. In Sense it should be GET (capital letters).

The explanation is related to GET vs. POST http methods. Behind the scene Sense actually converts a GET request to a HTTP POST (given that many browsers do not support HTTP GET requests with a request body). This means that, even if you write GET, the actual http request is a POST.

Because Sense has the autocomplete that forces upper case letters for request methods, it uses the same upper case letters when deciding if it's a GET (and not a lowercase get) request together with a request body. If it is, then that request is transformed to a POST one. If it compares the request method and decides is not a GET it sends the request as is, meaning with a get method and with a body. Since the body is ignored, what reaches Elasticsearch will be a test2/drug/_search which is basically a match_all.

这篇关于对弹性搜索查询感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆