Elasticsearch 多个值和多个字段匹配

问题描述 投票:0回答:0

从 solr 迁移到 Elasticsearch 我一直在尝试使用带有 bool 和 Should 的必须查询,但我未能获得结果。 下面提到的是solr查询

((source:6 OR source:48 OR source:66 OR source:46 OR source:2 OR source:58 OR source:56 OR source:14 OR source:13 OR source:24 OR source:27 OR source:16 OR source:45 OR source:53 OR source:57 OR source:69 OR source:163 OR source:121 OR source:137 OR source:150 OR source:151 OR source:152 OR source:154 OR source:155 OR source:156 OR source:158 OR source:159 OR source:161 OR source:162 OR source:164 OR source:166 OR source:168 OR source:169 OR source:174 OR source:175 OR source:176 OR source:204 OR source:202 OR source:211 OR source:209 OR source:201 OR source:212) AND (content:severe OR content:zxAMLzx OR content:zxDGHzx OR content:zxAFABzx OR content:zxBSHDzx) AND (dbname:docs) AND (specialties:*,28,*) AND (rootlineage:diagnosis) AND (agegroups:*,10,*) AND (sex:"male" OR sex:N) AND (pregnancy:*) AND (regions:*,12,*))

我将其转换为 Elasticsearch 查询

GET my_index_name/_search 
{
  "size": 50, 
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "source.keyword": [6, 48, 66, 46, 2, 58, 56, 14, 13, 24, 27, 16, 45, 53, 57, 69, 163, 121, 137, 150, 151, 152, 154, 155, 156, 158, 159, 161, 162, 164, 166, 168, 169, 174, 175, 176, 204, 202, 211, 209, 201, 212]
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "content": {
                    "query": "severe",
                    "analyzer": "query_analyzer"
                  }
                }
              },
              {
                "match": {
                  "content": {
                    "query": "zxAMLzx",
                    "analyzer": "query_analyzer"
                  }
                  
                }
              },
              {
                "match": {
                  "content": {
                    "query": "zxDGHzx",
                    "analyzer": "query_analyzer"
                  }
                  
                }
              },
              {
                "match": {
                  "content": {
                    "query": "zxAFABzx",
                    "analyzer": "query_analyzer"
                  }
                }
              },
              {
                "match": {
                  "content": {
                    "query": "zxBSHDzx",
                    "analyzer": "query_analyzer"
                  }
                }
              }
            ]
          }
        },
        {
          "term": {
            "dbname.keyword": "docs"
          }
        },
        {
          "wildcard": {
            "specialties.keyword": "*28*"
          }
        },
        {
          "term": {
            "rootlineage.keyword": "diagnosis"
          }
        },
        {
          "wildcard": {
            "agegroups.keyword": "*10*"
          }
        },
        {
          "terms": {
            "sex.keyword": ["male", "N"]
          }
        },
        {
          "wildcard": {
            "pregnancy.keyword": "*"
          }
        },
        {
          "wildcard": {
            "regions.keyword": "*12*"
          }
        }
      ]
    }
  },
  "_source": ["id","title","dbname","source","category","system_id","systems"]
}

映射是这样的

{
  "mappings": {
    "_doc": {
      "dynamic": "false",
      "properties": {
        "agegroups": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "category": {
          "type": "integer"
        },
        "content": {
          "type": "text",
          "analyzer": "index_analyzer"
        },
        "dbname": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "id": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "pregnancy": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "regions": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "rootlineage": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "sex": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "source": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "specialties": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "system_id": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "systems": {
          "type": "keyword",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          }
        },
        "title": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            }
          },
          "analyzer": "index_analyzer"
        }
      }
    }
  }
}

我得到了结果,但其中一些与 solr 结果匹配 但我希望所有 50 个文档应该以相同的顺序匹配

database elasticsearch migration
© www.soinside.com 2019 - 2024. All rights reserved.