Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/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 按子串匹配_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 按子串匹配,elasticsearch,elasticsearch" /> elasticsearch 按子串匹配,elasticsearch,elasticsearch" />

elasticsearch 按子串匹配

elasticsearch 按子串匹配,elasticsearch,elasticsearch,我需要获取Description字段包含子字符串28/859的文档。我的问题是: { "explain": true, "query": { "bool":{ "filter":{ "bool":{"should":[{"query_string":{"default_field":"Description","query":"28//859", "analyzer

我需要获取
Description
字段包含子字符串
28/859
的文档。我的问题是:

{
  "explain": true,
  "query": {
    "bool":{
      "filter":{
        "bool":{"should":[{"query_string":{"default_field":"Description","query":"28//859", 
                                           "analyzer": "keyword"}}]}},
      "must_not":{"exists":{"field":"ParentId"}}}
  }
}
我通过以下方式获得文件:

  • 28/859
    Description
    字段中(很好)
  • 但是我也可以在
    Description
    字段中获取带有
    28
    的文档(我不需要它)
如何获取仅包含子字符串
28/859
的文档

更新:解释示例:

{
        "_shard": "[tech_places][4]",
        "_node": "u7QI_gjjRXy4-xdqnK2KMw",
        "_index": "tech_places",
        "_type": "entity",
        "_id": "8403",
        "_score": 0.0,
        "_source": {
          "Id": 8403,
          "Name": "RETE-43424",
          "Description": "SRF-10kv №28 VISO",
          "ParentId": null,
          "OrganizationId": 12,
          "OrganizationPath": "12_27",
          "LocationId": 27,
          "Classification": "",
          "Type": "A",
          "Status": 0,
          "MaintenanceObjectId": null,
          "TreePath": "8403"
        },
        "_explanation": {
          "value": 0.0,
          "description": "sum of:",
          "details": [
            {
              "value": 0.0,
              "description": "match on required clause, product of:",
              "details": [
                {
                  "value": 0.0,
                  "description": "# clause",
                  "details": []
                },
                {
                  "value": 0.0,
                  "description": "sum of:",
                  "details": [
                    {
                      "value": 0.0,
                      "description": "weight(Description:28 in 35112) [], result of:",
                      "details": [
                        {
                          "value": 0.0,
                          "description": "score(doc=35112,freq=1.0), with freq of:",
                          "details": [
                            {
                              "value": 1.0,
                              "description": "termFreq=1.0",
                              "details": []
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      },

您可以为此使用
空白
分析器。使用
description
属性创建/更新映射,如下所示:

{
  "description": {
    "type": "text",
    "analyzer": "whitespace"
  }
}
这将确保像28/859这样的东西被视为s的单个令牌。您甚至可以使用正则表达式创建自己的自定义标记器/分析器。然后,您可以使用下面的查询来获得所需的结果:

{
  "query": {
    "query_string": {
      "default_field": "description",
      "query": "28\\/859"
    }
  }
}
应该符合要求

示例代码:

GET <indexname>/_search
{

  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "Description": """28/859"""
          }
        }
      ]
    }
  }
}
GET/\u搜索
{
“查询”:{
“布尔”:{
“必须”:[
{
“匹配短语”:{
说明:“28/859”
}
}
]
}
}
}

您能为查询添加explain:true并显示输出吗?@mystion,我已经更新了我的问题。它仅在
28/859
完整
描述
时有效,但在我的情况下,它只是一个子字符串。您尝试过吗?当28/859是相同顺序的字符串的一部分时,这意味着用于字段描述。不过,您也可以尝试以下操作:
GET/_search{“query”:{“bool”:{“must”:[{“match_phrase”:{“Description”:“28”},{“match_phrase”:{“Description”:“/859”}}}}谢谢,它对我有帮助。