elasticsearch - 当查询包含 “IN”前缀时,为什么 Elasticsearch 不返回结果?

标签 elasticsearch lucene kibana elastic-stack

下面的Elastic Query不为我的应用程序返回任何结果

"query" : {
  "bool" : {
    "must" : [
      {
        "simple_query_string" : {
          "query" : "IN-123456",
          "fields" : [
            "field1.auto^1.0",
            "field2.auto^1.0"
          ],
          "flags" : -1,
          "default_operator" : "AND",
          "analyze_wildcard" : false,
          "auto_generate_synonyms_phrase_query" : true,
          "fuzzy_prefix_length" : 0,
          "fuzzy_max_expansions" : 50,
          "fuzzy_transpositions" : true,
          "boost" : 1.0
        }
      }],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
}

请注意,我在 flex 数据源中存在带有与field2匹配的文本“IN-123456”的文档。
我可以搜索与“123456”相同的文档作为查询中的文本。

以下是使用的索引
{
  "document_****": {
    "aliases": {
      "document": {}
    },
    "mappings": {
      "_doc": {
        "dynamic": "strict",
        "date_detection": false,
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "field2": {
            "type": "keyword",
            "fields": {
              "auto": {
                "type": "text",
                "analyzer": "autocomplete",
                "search_analyzer": "standard"
              }
            }
          },

        }
      }
    },
    "settings": {
      "index": {
        "number_of_shards": "5",
        "provided_name": "document_***",
        "creation_date": "1****",
        "analysis": {
          "filter": {
            "autocomplete_filter_30": {
              "type": "edge_ngram",
              "min_gram": "1",
              "max_gram": "30"
            },
            "autocomplete_filter": {
              "type": "edge_ngram",
              "min_gram": "1",
              "max_gram": "20"
            }
          },
          "analyzer": {
            "autocomplete": {
              "filter": [
                "lowercase",
                "stop",
                "autocomplete_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "autocomplete_30": {
              "filter": [
                "lowercase",
                "stop",
                "autocomplete_filter_30"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "autocomplete_nonstop": {
              "filter": [
                "lowercase",
                "autocomplete_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "***",
        "version": {
          "created": "6020499"
        }
      }
    }
  }
}

注意:出于 secret 原因,很少用*替换值

最佳答案

检查您的映射。下面的查询工作正常。

POST v_upload_branch/_doc
{
  "branch_name":"IN-123456", 
  "branch_head":"Chennai", 
}

GET v_upload_branch/_search
{
"query" : {
  "bool" : {
    "must" : [
      {
        "simple_query_string" : {
          "query" : "IN-123456",
          "fields" : [
            "branch_head^1.0",
            "branch_name^1.0"
          ],
          "flags" : -1,
          "default_operator" : "AND",
          "analyze_wildcard" : false,
          "auto_generate_synonyms_phrase_query" : true,
          "fuzzy_prefix_length" : 0,
          "fuzzy_max_expansions" : 50,
          "fuzzy_transpositions" : true,
          "boost" : 1.0
        }
      }],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
}

以下是使用的索引
{
  "document_****": {
    "aliases": {
      "document": {}
    },
    "mappings": {
      "_doc": {
        "dynamic": "strict",
        "date_detection": false,
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "field2": {
            "type": "keyword",
            "fields": {
              "auto": {
                "type": "text",
                "analyzer": "autocomplete",
                "search_analyzer": "standard"
              }
            }
          },

        }
      }
    },
    "settings": {
      "index": {
        "number_of_shards": "5",
        "provided_name": "document_***",
        "creation_date": "1****",
        "analysis": {
          "filter": {
            "autocomplete_filter_30": {
              "type": "edge_ngram",
              "min_gram": "1",
              "max_gram": "30"
            },
            "autocomplete_filter": {
              "type": "edge_ngram",
              "min_gram": "1",
              "max_gram": "20"
            }
          },
          "analyzer": {
            "autocomplete": {
              "filter": [
                "lowercase",
                "stop",
                "autocomplete_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "autocomplete_30": {
              "filter": [
                "lowercase",
                "stop",
                "autocomplete_filter_30"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "autocomplete_nonstop": {
              "filter": [
                "lowercase",
                "autocomplete_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "***",
        "version": {
          "created": "6020499"
        }
      }
    }
  }
}

注意:出于 secret 原因,很少用*替换值

关于elasticsearch - 当查询包含 “IN”前缀时,为什么 Elasticsearch 不返回结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59260485/

相关文章:

lucene - lucene的复合文件有什么好处

java - Elasticsearch 正在使用旧的 java 版本运行

elasticsearch - 流程在Elasticsearch查询中如何工作?

solr 将 java 源文件索引为文本

solr - 如何使用 apache solr 索引文本文件

rest - 以 REST、curl 形式表示 Kibana 查询

elasticsearch - 按文本字段分组的 Elastic Search 抛出错误 Fielddata 默认在文本字段上禁用

elasticsearch - 在Ubuntu 17.10上设置Kibana

database - Elasticsearch : Parent child vs Nested Document

elasticsearch - 在elasticsearch中在过滤器中使用minimum_match