Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Search 如何在弹性搜索中使用split_on_空格?_Search_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Search,elasticsearch" /> elasticsearch,Search,elasticsearch" />

Search 如何在弹性搜索中使用split_on_空格?

Search 如何在弹性搜索中使用split_on_空格?,search,elasticsearch,Search,elasticsearch,我想在搜索查询中对空格使用split\u,但无法解决这个问题。查询将有一个类似“hello world”的字符串。我不想分割查询词首先,确保不分析要搜索的字段的映射。这样ES就不会分析字段中的单词并将其存储为单个文本 因此,您的映射将类似于: curl -XPUT localhost:9200/index_name -d '{ "mappings": { "type_name": { "properties": {

我想在搜索查询中对空格使用split\u,但无法解决这个问题。查询将有一个类似“hello world”的字符串。我不想分割查询词

首先,确保不分析要搜索的字段的映射。这样ES就不会分析字段中的单词并将其存储为单个文本

因此,您的映射将类似于:

    curl -XPUT localhost:9200/index_name -d '{
      "mappings": {
       "type_name": {
           "properties": {
               "field_to_search": {
                   "type": "string",
                   "index": "not_analyzed"
               },
            ...(other fields)
          }
       }
    }
    }
然后可以对字段执行术语查询

curl -XPOST localhost:9200/index_name/type_name/_search -d '{
    "query": {
        "term": {
           "field_to_search": "hello world"
         }
     }
 }
您可以查看elasticsearch的术语查询和匹配查询之间的区别,以了解为什么需要术语查询