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
如何在ElasticSearch中正确搜索属性/字段名中有空格的文档?_Search_Curl_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Search,Curl,elasticsearch" /> elasticsearch,Search,Curl,elasticsearch" />

如何在ElasticSearch中正确搜索属性/字段名中有空格的文档?

如何在ElasticSearch中正确搜索属性/字段名中有空格的文档?,search,curl,elasticsearch,Search,Curl,elasticsearch,我相信我在搜索属性/字段名中有空格的字符串时遇到了问题 我使用curl命令成功批量加载了一些人员/个人记录: curl -XPOST localhost:9200/enterprise/person/_bulk --data-binary @./JSON_DATA/people1.json curl -XGET 'http://localhost:9200/enterprise/person/_search?q="First Name":jane' 数据如下: {"index":{}} {

我相信我在搜索属性/字段名中有空格的字符串时遇到了问题

我使用curl命令成功批量加载了一些人员/个人记录:

curl -XPOST localhost:9200/enterprise/person/_bulk --data-binary  @./JSON_DATA/people1.json
curl -XGET 'http://localhost:9200/enterprise/person/_search?q="First Name":jane'
数据如下:

{"index":{}}
{"Last Name": "Doe", "First Name": "Jane", "my_ID": "Person:=Jane Doe", "Age": "21"}
{"index":{}}
{"Last Name": "Smith", "First Name": "Joe", "my_ID": "Person:=Joe Smith", "Age": "23"}
{"index":{}}
{"Last Name": "Smiley", "First Name": "Bob", "my_ID": "Person:=Bob Smiley", "Age": "52"}
{"index":{}}
{"Last Name": "Doe", "First Name": "John", "my_ID": "Person:=John Doe", "Age": "32"}
curl -XGET 'http://localhost:9200/enterprise/person/_search?pretty' -d '{
  "query": { "match": { "First Name": "Jane" } } 
}'
我可以成功搜索所有文档记录并查看它们是否在索引中

但是,我随后尝试使用以下curl命令专门搜索属性“First Name”中包含字符串“jane”的任何人:

curl -XPOST localhost:9200/enterprise/person/_bulk --data-binary  @./JSON_DATA/people1.json
curl -XGET 'http://localhost:9200/enterprise/person/_search?q="First Name":jane'
这与以下语句不符:

curl: (52) Empty reply from server
我相信问题与我的查询语法以及如何在字符串“firstname”中表示空格有关。然而,我不知道如何正确地修复它

我还尝试使用以下命令使用表示空间的搜索:

curl -XGET 'http://localhost:9200/enterprise/person/_search?q=first%20name:jane'
在这种情况下,我得到了一个不同的结果,但它似乎仍然找不到她,因为她出现在搜索所有结果中:

{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

非常感谢您的帮助谢谢。

事实证明,更安全的搜索方法是使用查询和匹配命令,如下所示:

{"index":{}}
{"Last Name": "Doe", "First Name": "Jane", "my_ID": "Person:=Jane Doe", "Age": "21"}
{"index":{}}
{"Last Name": "Smith", "First Name": "Joe", "my_ID": "Person:=Joe Smith", "Age": "23"}
{"index":{}}
{"Last Name": "Smiley", "First Name": "Bob", "my_ID": "Person:=Bob Smiley", "Age": "52"}
{"index":{}}
{"Last Name": "Doe", "First Name": "John", "my_ID": "Person:=John Doe", "Age": "32"}
curl -XGET 'http://localhost:9200/enterprise/person/_search?pretty' -d '{
  "query": { "match": { "First Name": "Jane" } } 
}'
这确保了不必处理URL中的空格等特殊字符