elasticsearch - Elasticsearch :使用字段时查询字符串的结果不同

标签 elasticsearch nest

我们有一个 flex 搜索5.5设置。我们使用nest通过C#执行查询。

执行以下查询时:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "00917751"
          }
        }
      ]
    }
  }
}


我们得到期望的结果:以该数字作为标识符的结果。

使用以下查询时:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "00917751",
            "fields": [
              "searchReference",
              "searchIdentifier",
              "searchObjectNo",
              "searchBrand",
              "searchExtSerNo"
            ]
          }
        }
      ]
    }
  }
}


我们没有结果。

我们要搜索的值在字段searchIndentifier中,并且值为“1-00917751”。

我们有一个名为“final”的自定义分析器

.Custom("final", cu => cu .Tokenizer("keyword").Filters(new List() { "lowercase" }))



字段searchIndentifier上没有设置自定义分析器。我们尝试在其中添加空白标记器,但这没有什么区别。

当我们尝试使用查询“S328”搜索值“S328-25”时,另一个名为“searchObjectNo”的字段确实起作用。这些字段完全相同。

这里有什么想法吗?

另一个问题。在第一个查询中,当我们搜索1-00917751(不带引号)时,会得到很多结果。但是我们认为这是因为关键字标记符吗?

谢谢

肖夫

索引设置和映射:
{
  "inventoryitems": {
    "aliases": {},
    "mappings": {
      "inventoryobject": {
        "properties": {
          "articleGroups": {
            "type": "nested",
            "properties": {
              "id": {
                "type": "long"
              }
            }
          },
          "articleId": {
            "type": "long"
          },
          "articleNumber": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          },
          "brand": {
            "type": "text",
            "analyzer": "final"
          },
          "catalogues": {
            "type": "nested",
            "properties": {
              "articleGroupId": {
                "type": "long"
              },
              "articleGroupName": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              },
              "id": {
                "type": "long"
              },
              "name": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              }
            }
          },
          "details": {
            "type": "nested",
            "properties": {
              "actualState": {
                "type": "double"
              },
              "allocation": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              },
              "available": {
                "type": "double"
              },
              "batch": {
                "type": "text",
                "analyzer": "final"
              },
              "calibrationDate": {
                "type": "date"
              },
              "expected": {
                "type": "double"
              },
              "externalSerialNumber": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "id": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "inReturn": {
                "type": "double"
              },
              "inventory": {
                "type": "double"
              },
              "isInMobileCarrier": {
                "type": "boolean"
              },
              "locationDetail": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "locationId": {
                "type": "long"
              },
              "locationName": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              },
              "locationType": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              },
              "lotId": {
                "type": "long"
              },
              "mobileCarrierCode": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              },
              "mobileCarrierId": {
                "type": "long"
              },
              "ownerCode": {
                "type": "text",
                "analyzer": "final"
              },
              "requested": {
                "type": "double"
              },
              "reserved": {
                "type": "double"
              },
              "storeLocationId": {
                "type": "long"
              },
              "thicknessCode": {
                "type": "text",
                "analyzer": "final"
              },
              "weldedMark": {
                "type": "text",
                "analyzer": "final"
              }
            }
          },
          "docNo": {
            "type": "long"
          },
          "hasStock": {
            "type": "boolean"
          },
          "id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "identifier": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          },
          "inventoryItemType": {
            "properties": {
              "name": {
                "type": "text",
                "analyzer": "final",
                "fielddata": true
              }
            }
          },
          "mobileCarrierId": {
            "type": "long"
          },
          "name": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          },
          "objectNumber": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          },
          "quantity": {
            "type": "double"
          },
          "reference": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          },
          "searchBrand": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "searchExtSerNo": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "searchIndentifier": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "searchName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "searchObjectNo": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "searchReference": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "sortNumber": {
            "type": "long"
          },
          "stockUnit": {
            "type": "text",
            "boost": 1.5,
            "analyzer": "final"
          }
        }
      }
    },
    "settings": {
      "index": {
        "number_of_shards": "3",
        "provided_name": "inventoryitems",
        "creation_date": "1539253308319",
        "analysis": {
          "analyzer": {
            "final": {
              "filter": [
                "lowercase"
              ],
              "type": "custom",
              "tokenizer": "keyword"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "Kb5KuYEiR5GQqgBPVYjJfA",
        "version": {
          "created": "5050299"
        }
      }
    }
  }
}

最佳答案

答案很简单:在映射中,您的字段名为searchIndentifier,而在查询中,您使用的字段名为searchIdentifier,该字段不存在;-)

关于elasticsearch - Elasticsearch :使用字段时查询字符串的结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52756786/

相关文章:

spring-boot - ElasticsearchRepository是否具有获取id最大值的方法?如果没有,如何编写查询以获取id的最大值

twitter - 如果在Elasticsearch中使用批量处理器不存在索引

elasticsearch - 使用嵌套 Elasticsearch 客户端生成带有命名字段的 QueryString

symfony - 使用fos:elastica:populate时检测到循环引用

elasticsearch - 尝试启动Logstash时如何解决问题 'Unsupported major.minor version 52.0'

长查询的 ElasticSearch、Nest 和超时

.net - 如何在 Elasticsearch 的 Nest.Net 中搜索 GUID?

c# - ElasticSearch对所有字段进行模糊搜索,增强精确匹配并增强其他各种匹配条件

elasticsearch - 如何使用NEST与ElasticSearch进行引导匹配

elasticsearch - Elasticsearch多数据路径磁盘已满