Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 查询必须完全匹配两个字段,don';不分析_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 查询必须完全匹配两个字段,don';不分析,elasticsearch,elasticsearch" /> elasticsearch 查询必须完全匹配两个字段,don';不分析,elasticsearch,elasticsearch" />

elasticsearch 查询必须完全匹配两个字段,don';不分析

elasticsearch 查询必须完全匹配两个字段,don';不分析,elasticsearch,elasticsearch,我尝试了几种不同的方法来执行一个简单的get请求,在两个不同的属性上进行过滤,示例: "query": { "filtered": { "filter": { "bool": { "must": [ { "term": { "email": "erik.landvall@ex

我尝试了几种不同的方法来执行一个简单的get请求,在两个不同的属性上进行过滤,示例

"query": {
    "filtered": {
        "filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "email": "erik.landvall@example.com"
                        }
                    },
                    {
                        "term": {
                            "password": "bb3810356e9b60cf6..."
                        }
                    }
                ]
            }
        },
        "query": {
            "match_all": []
        }
    }
}
问题是我得不到任何回报。据我所知,这是因为ElasticSearch分析电子邮件字段,导致查询失败。因此,如果我使用术语
erik.landvall
而不是完整的电子邮件地址,它将与文档匹配——这证实了正在发生的事情

创建索引时,我可以将属性定义为
type:string
index:not_analysis
。但是如果我想在不同的上下文中搜索email属性呢?因此,在我看来,应该有一种方法来指定我想要在查询中过滤属性的实际值。不过,我看不出这样的查询是怎样的

查询时是否可以强制Elasticsearch使用“
不分析”
?如果是,那么如何使用?

用于此目的。您必须直接访问存储在其中的JSON。尝试以下查询

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": {
                "inline" : "_source.email==param1 && _source.password==param2",
                "params" : {
                    "param1" : "erik.landvall@example.com",
                    "param2" : "bb3810356e9b60cf6"
                }
            }
        }
      }
    }
  }
}
你需要这样做。将
script.inline:on
添加到yml文件并重新启动节点


如果这种查询是相当常规的,那么最好按照其他人在评论中的建议重新编制数据索引。

不可能打开/关闭分析或不打开/关闭分析,方法是“转换”字段以进行所需的分析


}“

我没有太多时间回答您的问题,但请看这里:我想您也会对此感兴趣:-您可以为一个输入json字段指定多个具有不同映射的字段。如果没有人会更深入地回答你的问题,我明天就会回答。@Adam这两个建议似乎都是为了在创建索引时在查询之前指定映射。我的问题是,是否可以在不更改索引的情况下指定它。我从未使用过它,但可以在查询级别指定分析器,但并非所有查询都允许。如果您不想分析输入字符串,那么只需要指定关键字分析器。你可以在这里阅读更多:或者看看这里(查询中的analyzer字段):@Adam我在这里得到了一些答案,但没有一个符合我的需要。但我还没有放弃。我尝试了
关键字
分析器,但它在email字段上根本不匹配,我的理解是,在持久化时,字段已经被分析过了,在查询时,没有
@
符号可供比较。使用
zero\u terms\u查询进行了一些测试。到目前为止,它似乎做了我需要的,但不确定它将如何处理,如果有2封电子邮件在同一个领域的例子。
关键字
分析器似乎是我想要使用的,但有什么东西把我搞砸了。这不可能在yml设置文件中作为默认设置来完成吗?因此,
not_analysisd
总是存在吗?@ErikLandvall我看到的唯一方法是定义动态模板
curl -XPUT 'localhost:9200/my_index?pretty' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "city": {
          "type": "string",
          "fields": {
            "raw": { 
              "type":  "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -d'
{
  "city": "New York"
}'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -d'
{
  "city": "York"
}'
curl -XGET 'localhost:9200/my_index/_search?pretty' -d'
{
  "query": {
    "match": {
      "city": "york" 
    }
  },
  "sort": {
    "city.raw": "asc" 
  },
  "aggs": {
    "Cities": {
      "terms": {
        "field": "city.raw" 
      }
    }
  }