Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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

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
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch Elasticsearch:查询所有工作,但不查询特定字段_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Field_Return Value_Analyzer - Fatal编程技术网 elasticsearch Elasticsearch:查询所有工作,但不查询特定字段,elasticsearch,field,return-value,analyzer,elasticsearch,Field,Return Value,Analyzer" /> elasticsearch Elasticsearch:查询所有工作,但不查询特定字段,elasticsearch,field,return-value,analyzer,elasticsearch,Field,Return Value,Analyzer" />

elasticsearch Elasticsearch:查询所有工作,但不查询特定字段

elasticsearch Elasticsearch:查询所有工作,但不查询特定字段,elasticsearch,field,return-value,analyzer,elasticsearch,Field,Return Value,Analyzer,当我查询所有字段的数据时,Elasticsearch返回两个文档(两个文档中只有一个字段)。但是,当我执行相同的查询时,除了将要查询的字段从\u all更改为返回文档中某个字段的名称外,Elasticsearch不返回任何内容。这似乎发生在query\u字符串query以及此处显示的match查询中。你知道这是怎么回事吗?怎么解决 这是映射 analyzertestpatternsemi: { mappings: { content: { properties: {

当我查询所有字段的数据时,Elasticsearch返回两个文档(两个文档中只有一个字段)。但是,当我执行相同的查询时,除了将要查询的字段从
\u all
更改为返回文档中某个字段的名称外,Elasticsearch不返回任何内容。这似乎发生在
query\u字符串
query以及此处显示的
match
查询中。你知道这是怎么回事吗?怎么解决

这是映射

analyzertestpatternsemi: {
  mappings: {
    content: {
      properties: {
        field: {
          type: string
          store: true
          term_vector: with_positions_offsets
          index_analyzer: analyzer_name
        }
        field2: {
          type: string
          store: true
          index_analyzer: analyzer_name
        }
      }
    }
  }
}
这是设置

{
  analyzertestpatternsemi: {
    settings: {
      index: {
        uuid: _W55phRKQ1GylWU5JleArg
          analysis: {
            analyzer: { 
              whitespace: {
                type: custom
                fields: [
                  lowercase
                ]
                tokenizer: whitespace
              }
              analyzer_name: {
                preserve_original: true
                type: pattern
                pattern: ;
              }
            }
          }
          number_of_replicas: 1
          number_of_shards: 5
          version: {
          created: 1030299
          }
        }
      }
    }
  }
{
  _index: analyzertestpatternsemi
  _type: content
  _id: 3
  _version: 1
  found: true
   _source: {
    field2: Hello, I am Paul; George
  }
}
{
  took: 2
  timed_out: false
  _shards: {
    total: 2
    successful: 2
    failed: 0
  }
  hits: {
    total: 2
    max_score: 0.4375
    hits: [
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 2
        _score: 0.4375
        _source: {
          field: Hello, I am Paul; George
        }
      }
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 3
        _score: 0.13424811
        _source: {
          field2: Hello, I am Paul; George
        }
      }
    ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
文档

{
  analyzertestpatternsemi: {
    settings: {
      index: {
        uuid: _W55phRKQ1GylWU5JleArg
          analysis: {
            analyzer: { 
              whitespace: {
                type: custom
                fields: [
                  lowercase
                ]
                tokenizer: whitespace
              }
              analyzer_name: {
                preserve_original: true
                type: pattern
                pattern: ;
              }
            }
          }
          number_of_replicas: 1
          number_of_shards: 5
          version: {
          created: 1030299
          }
        }
      }
    }
  }
{
  _index: analyzertestpatternsemi
  _type: content
  _id: 3
  _version: 1
  found: true
   _source: {
    field2: Hello, I am Paul; George
  }
}
{
  took: 2
  timed_out: false
  _shards: {
    total: 2
    successful: 2
    failed: 0
  }
  hits: {
    total: 2
    max_score: 0.4375
    hits: [
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 2
        _score: 0.4375
        _source: {
          field: Hello, I am Paul; George
        }
      }
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 3
        _score: 0.13424811
        _source: {
          field2: Hello, I am Paul; George
        }
      }
    ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}

获取
\u id
的术语向量

george
你好,我是paul

“\u all”查询

curl -XGET http://localhost:9200/analyzertestpatternsemi/_search?
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "_all": {
              "query": "george",
              "type": "phrase"
            }
          }
        }
      ]
    }
  }
}
“所有”查询结果

{
  analyzertestpatternsemi: {
    settings: {
      index: {
        uuid: _W55phRKQ1GylWU5JleArg
          analysis: {
            analyzer: { 
              whitespace: {
                type: custom
                fields: [
                  lowercase
                ]
                tokenizer: whitespace
              }
              analyzer_name: {
                preserve_original: true
                type: pattern
                pattern: ;
              }
            }
          }
          number_of_replicas: 1
          number_of_shards: 5
          version: {
          created: 1030299
          }
        }
      }
    }
  }
{
  _index: analyzertestpatternsemi
  _type: content
  _id: 3
  _version: 1
  found: true
   _source: {
    field2: Hello, I am Paul; George
  }
}
{
  took: 2
  timed_out: false
  _shards: {
    total: 2
    successful: 2
    failed: 0
  }
  hits: {
    total: 2
    max_score: 0.4375
    hits: [
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 2
        _score: 0.4375
        _source: {
          field: Hello, I am Paul; George
        }
      }
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 3
        _score: 0.13424811
        _source: {
          field2: Hello, I am Paul; George
        }
      }
    ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
***相同的查询,但在字段“field”中搜索

“字段”查询结果

{
  analyzertestpatternsemi: {
    settings: {
      index: {
        uuid: _W55phRKQ1GylWU5JleArg
          analysis: {
            analyzer: { 
              whitespace: {
                type: custom
                fields: [
                  lowercase
                ]
                tokenizer: whitespace
              }
              analyzer_name: {
                preserve_original: true
                type: pattern
                pattern: ;
              }
            }
          }
          number_of_replicas: 1
          number_of_shards: 5
          version: {
          created: 1030299
          }
        }
      }
    }
  }
{
  _index: analyzertestpatternsemi
  _type: content
  _id: 3
  _version: 1
  found: true
   _source: {
    field2: Hello, I am Paul; George
  }
}
{
  took: 2
  timed_out: false
  _shards: {
    total: 2
    successful: 2
    failed: 0
  }
  hits: {
    total: 2
    max_score: 0.4375
    hits: [
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 2
        _score: 0.4375
        _source: {
          field: Hello, I am Paul; George
        }
      }
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 3
        _score: 0.13424811
        _source: {
          field2: Hello, I am Paul; George
        }
      }
    ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
相同的查询,但在字段“field2”中搜索

“字段2”查询结果

{
  analyzertestpatternsemi: {
    settings: {
      index: {
        uuid: _W55phRKQ1GylWU5JleArg
          analysis: {
            analyzer: { 
              whitespace: {
                type: custom
                fields: [
                  lowercase
                ]
                tokenizer: whitespace
              }
              analyzer_name: {
                preserve_original: true
                type: pattern
                pattern: ;
              }
            }
          }
          number_of_replicas: 1
          number_of_shards: 5
          version: {
          created: 1030299
          }
        }
      }
    }
  }
{
  _index: analyzertestpatternsemi
  _type: content
  _id: 3
  _version: 1
  found: true
   _source: {
    field2: Hello, I am Paul; George
  }
}
{
  took: 2
  timed_out: false
  _shards: {
    total: 2
    successful: 2
    failed: 0
  }
  hits: {
    total: 2
    max_score: 0.4375
    hits: [
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 2
        _score: 0.4375
        _source: {
          field: Hello, I am Paul; George
        }
      }
      {
        _index: analyzertestpatternsemi
        _type: content
        _id: 3
        _score: 0.13424811
        _source: {
          field2: Hello, I am Paul; George
        }
      }
    ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
{
  took: 0
  timed_out: false
  _shards: {
    total: 5
    successful: 5
    failed: 0
  }
  hits: {
    total: 0
    max_score: null
      hits: [ ]
  }
}
问题是您的“模式”标记器将文本拆分为
您好,我是paul
george
注意“george”前面的空格)。为了能够
george
匹配
,您需要去掉空白

这里有一种方法-使用模式标记器和自定义过滤器列表定义您自己的自定义分析器(其中“trim”是修剪标记前后的空白所需的添加项):


我使用multi_term类型以多种方式分析和存储字段。可以在这里找到它的文档 一个分析器可以为特定类型的查询或聚合提供所需的标记,另一个分析器可以为相同数据上的不同类型的查询提供所需的标记


我不知道为什么会发生这个错误(在原始问题中提到),但我试图实现的是使用分析器创建标记,标记之间以“;”作为分隔符。我希望这样做,这样我就可以根据标记(由“;”分隔的术语分组)进行热门聚合。但我希望能够使用单个单词(如标准分析器)搜索/查询数据,而不必查询整个标记(术语分组)。为了实现这一点,我刚刚将“field”的“type”和“field2”定义为“multi_field”,然后定义为子字段。一个子字段使用“标准”分析器和“分析器名称”(自定义模式分析器)。带有标准分析器的字段是将针对其运行查询的字段,而另一个字段(带有“analyzer_name”分析器)将用于聚合

问题实际上与查询有关。存储的两个令牌是“你好,我是保罗”和“乔治”

将“trim”过滤器添加到分析器“analyzer name”解决了查询“george”不返回任何内容的问题,因为没有“trim”分析器,存储的术语实际上是“george”

问题(James在11月6日的评论中指出,与Adrei Stefan在11月5日的回答相关)匹配查询在查询中使用以下内容时未返回文档:“你好”、“保罗”、“你好我是保罗”、“你好我是保罗”和“你好,我是保罗”解释如下

***这里的问题是查询。使用“标准”分析器(默认分析器)的匹配查询时。这意味着查询“hello”正在搜索令牌“hello”,但存储的令牌实际上是“hello,i am paul”,查询“hello i am paul”实际上搜索令牌“hello”、“i”、“anm”和“paul”,这些令牌与字段中存储的任何令牌都不匹配


在这种情况下,Elasticsearch只会在搜索词为“george”或“hello,我是paul”时返回文档。如果您使用这两个标记中的任何一个进行术语搜索,或者在analyzer设置为“关键字”的匹配查询中使用它们,则将返回文档。如果您将analyzer设置为“analyzer_name”,您还可以搜索“hello,我是paul”、“george”、“hello,我是paul;george”或这三个字母中的任何一个(大写)。

谢谢您的帮助。这确实解决了专门搜索“george”时的问题,但在搜索其他术语时,我仍然存在相同的问题(在搜索“_all”时返回文档,但在搜索“field”或“field2”时不返回文档)。“你好,我是保罗”。我试着搜索“你好”、“保罗”、“你好,我是保罗”、“你好,我是保罗”和“你好,我是保罗”;它们都没有返回任何东西。是的,有多种搜索方式,通过不同的标记分析和存储同一文本的多种方式。