在包含撇号的字段中搜索不会 return 结果 elasticsearch

search in fields containing apostrophe does not return results elasticsearch

我使用 elasticsearch 在包含撇号的字段上进行的搜索没有 returning 结果。 字段示例:Objet de l'opération de crédit 这是我的查询:

{
    "size": 100,
    "query": {
        "bool": {
            "must": [{
                    "match_phrase": {
                        "Objet de l'opération de crédit": {
                            "query": "SMD : Investissement locatif",
                            "slop": 0,
                            "zero_terms_query": "NONE",
                            "boost": 1.0
                        }
                    }
                }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
        }
    }
}

此查询没有 return 结果,并且仅针对带撇号的字段 请帮助我是 elasticsearch 的新手

TL;DR: 问题不是字段名称上的撇号,而是字段名称末尾的 space。

Elasticsearch 不会警告查询中拼写错误的不存在字段,只会 return 没有结果。

旧答案

如果您将要 return 的示例文档添加到该查询中,这将很有帮助,因为在测试文档中使用相同的值实际上是您发布的查询 return 结果。

如果没有这些信息,我可以猜测找不到该文档,因为您使用的是“match_phrase”,这意味着将整个内容匹配为一个短语,而 slop 0 意味着您不允许中间的单词, 或不同的词序。

我建议先尝试使用不太严格的查询。

POST test_alma/_search
{
  "query": {
    "match": {
      "Objet de l'opération de crédit": "SMD : Investissement locatif"
    }
  }
}

正在摄取文档

POST test_alma/_doc
{
   "Objet de l'opération de crédit": "SMD : Investissement locatif"
}

您的查询

POST test_alma/_search
{
  "size": 100,
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "Objet de l'opération de crédit": {
              "query": "SMD : Investissement locatif",
              "slop": 0,
              "zero_terms_query": "NONE",
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

回应

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.8630463,
    "hits" : [
      {
        "_index" : "test_alma",
        "_type" : "_doc",
        "_id" : "asod-ncBRP0FeAG5QeOY",
        "_score" : 0.8630463,
        "_source" : {
          "Objet de l'opération de crédit" : "SMD : Investissement locatif"
        }
      }
    ]
  }
}