0

在 ES 2.3.3 中,我正在处理的系统中的许多查询都使用 _all 字段。有时这些被注册到一个渗透索引,当在文档上运行渗透器时,_all 会自动生成。

在转换为 ES 5.X 时,_all 已被弃用,因此 _all 已被替换为包含我们实际关心的组件的 copy_to 字段,它对这些搜索非常有用。

将相同的查询注册到具有相同文档映射(包括 copy_to 字段)的渗透索引可以正常工作。但是,使用文档发送渗透查询永远不会导致 copy_to 字段的命中。

通过简单的字符串连接手动构建 copy_to 字段似乎可行,只是我希望能够 Query -> DocIndex 并获得与 Doc -> PercolateQuery 相同的结果......所以我只是在寻找一种方法让 ES 在被渗透的文档上自动生成 copy_to 字段。

4

1 回答 1

0

最终,ES 当然没有任何问题,在这里发布以防万一它对其他人有所帮助。在尝试生成一个更简单的示例以在此处发布详细信息时弄清楚了...基本上问题归结为这样一个事实,即尝试渗透渗透索引中不存在的类型的文档不会给出任何错误返回,但似乎应用了所有渗透查询而不应用任何映射,这只是令人困惑,因为它适用于简单的测试用例,但不适用于复杂的测试用例。这是一个例子:

  1. 从 copy_to 文档,生成一个带有 copy_to 映射的索引。看到对 copy_to 字段的查询有效。

    PUT my_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "first_name": {
              "type": "text",
              "copy_to": "full_name" 
            },
            "last_name": {
              "type": "text",
              "copy_to": "full_name" 
            },
            "full_name": {
              "type": "text"
            }
          }
        }
      }
    }
    
    PUT my_index/my_type/1
    {
      "first_name": "John",
      "last_name": "Smith"
    }
    
    GET my_index/_search
    {
      "query": {
        "match": {
          "full_name": { 
            "query": "John Smith",
            "operator": "and"
          }
        }
      }
    }
    
  2. 创建具有相同类型的渗透索引

    PUT /my_percolate_index
    {
      "mappings": {
        "my_type": {
          "properties": {
            "first_name": {
              "type": "text",
              "copy_to": "full_name" 
            },
            "last_name": {
              "type": "text",
              "copy_to": "full_name" 
            },
            "full_name": {
              "type": "text"
            }
          }
        },
        "queries": {
          "properties": {
            "query": {
              "type": "percolator"
            }
          }
        }
      }
    }
    
  3. 创建一个与我们在 copy_to 字段上的其他 percolate 查询匹配的 percolate 查询,以及仅查询基本未修改字段的第二个查询

    PUT /my_percolate_index/queries/1?refresh
    {
      "query": {
        "match": {
          "full_name": { 
            "query": "John Smith",
            "operator": "and"
          }
        }
      }
    }
    PUT /my_percolate_index/queries/2?refresh
    {
      "query": {
        "match": {
          "first_name": { 
            "query": "John"
          }
        }
      }
    }
    
  4. 搜索,但类型错误...即使没有与请求匹配的文档映射,基本字段 (first_name: John) 也会被命中

    GET /my_percolate_index/_search
    {
      "query" : {
        "percolate" : {
          "field" : "query",
          "document_type" : "non_type",
          "document" : {
            "first_name": "John",
            "last_name": "Smith"
          }
        }
      }
    }
    {"took":7,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":1,"max_score":0.2876821,"hits":[{"_index":"my_percolate_index","_type":"queries","_id":"2","_score":0.2876821,"_source":{
      "query": {
        "match": {
          "first_name": { 
            "query": "John"
          }
        }
      }
    }}]}}
    
  5. 发送正确的 document_type 并按预期查看两个匹配项

    GET /my_percolate_index/_search
    {
      "query" : {
        "percolate" : {
          "field" : "query",
          "document_type" : "my_type",
          "document" : {
            "first_name": "John",
            "last_name": "Smith"
          }
        }
      }
    }
    {"took":7,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":2,"max_score":0.51623213,"hits":[{"_index":"my_percolate_index","_type":"queries","_id":"1","_score":0.51623213,"_source":{
      "query": {
        "match": {
          "full_name": { 
            "query": "John Smith",
            "operator": "and"
          }
        }
      }
    }},{"_index":"my_percolate_index","_type":"queries","_id":"2","_score":0.2876821,"_source":{
      "query": {
        "match": {
          "first_name": { 
            "query": "John"
          }
        }
      }
    }}]}}
    
于 2018-04-10T04:13:21.703 回答