用于ElasticSearch的JSON:三个字段和三个查询

ef1yzkbh  于 2022-11-02  发布在  ElasticSearch
关注(0)|答案(1)|浏览(140)

有没有办法按query_string编写此查询?
(字段_one:“字一”或“字二”或“字三”)AND(字段一:“字_四”或“字_五”或“字_六”)AND(字段_二:“字_七”或“字_八”或“字_九”)
就像这样,但是有三个字段和三个查询?

"query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "fields": [
              "my_search_field"
              ],
            "query": "my_search_query"
          }
        }
        ]
    }
  }

我试着用filter写它:

"filter": [
        {
          "bool": {
            "filter": [
              {
                "bool": {
                  "should": should_phrases_a, #words by field_one
                  "minimum_should_match": 1
                }
              },
              {
                "bool": {
                  "should": should_phrases_b, #words by field_one
                  "minimum_should_match": 1
                }
              },
              {
                "bool": {
                  "should": should_phrases_c, #words by field_two
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
        ]

其中_phase_a/B/c应类似于以下内容的列表:

{"bool": {"should": [{
                            "match_phrase": {
                              "field_one": "word_one"
                            }
                          }
                        ],
                        "minimum_should_match": 1
                      }
                    }

但它对我不起作用,只适用于one_field交集(没有与should_phrases_c的部分):
(字段_one:“字一”或“字二”或“字三”)AND(字段一:“字_四”或“字_五”或“字_六”)

kd3sttzy

kd3sttzy1#

您可以在查询中指定字段

查询

{
  "query": {
    "query_string": {
      "query": """
                  (field_one:word_one OR word_two OR word_three)
              AND (field_one:word_four OR word_five OR word_six)
              AND (field_two:word_seven OR word_eigth OR word_nine)
              """
    }
  }
}

相关问题