Skip to content

Conversation

@atsushi-matsui
Copy link

@atsushi-matsui atsushi-matsui commented Jun 24, 2024

Add omit_zero_term_query option to the bool query.
By giving this option, I hope bool queries will ignore queries with 0 token.
This behavior is the same as query_string and simple_query_string_query.

close #110080

@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v8.15.0 labels Jun 24, 2024
@atsushi-matsui atsushi-matsui changed the title feat: Add new option omit_zero_term_query to boolquery feat: Add new option omit_zero_term_query to bool query Jun 24, 2024
@atsushi-matsui atsushi-matsui marked this pull request as ready for review June 24, 2024 01:07
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Jun 24, 2024
@atsushi-matsui atsushi-matsui force-pushed the feature/feat/omit-zero-term-query branch from 082c4b3 to 1c46d89 Compare June 24, 2024 03:59
@atsushi-matsui
Copy link
Author

I checked the operation in a local environment.

  • index settings
curl -u elastic:password -X PUT "http://localhost:9200/my_index"

curl -u elastic:password -X POST "localhost:9200/my_index/_close?pretty"

curl -u elastic:password -X PUT "http://localhost:9200/my_index/_settings" -H 'Content-Type: application/json' -d'
{
  "analysis": {
    "filter": {
      "my_synonym_filter": {
        "type": "synonym",
        "synonyms": [
          "fast, quick"
        ]
      },
      "my_stop_filter": {
        "type": "stop",
        "stopwords": "_english_" 
      }
    },
    "analyzer": {
      "my_custom_analyzer": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "lowercase",
          "my_synonym_filter",
          "my_stop_filter"
        ]
      }
    }
  }
}
'

curl -u elastic:password  -X PUT "localhost:9200/my_index/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "my_custom_analyzer"
    },
    "release_date": {
      "type": "date"
    },
    "views": {
      "type": "integer"
    }
  }
}
'

curl -u elastic:password  -X POST "localhost:9200/my_index/_open?pretty"
  • post document
curl -u elastic:password -X POST "http://localhost:9200/my_index/_doc/1" -H 'Content-Type: application/json' -d'
{
  "title": "Quick the Brown Fox",
  "release_date": "2023-01-01",
  "views": 123
}
'
  • search with omit_zero_term_query option
    request
curl -X GET -u elastic:password "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "profile": true,
  "query": {
    "bool": {
      "omit_zero_term_query": true,
      "must": [
        {
          "multi_match": {
            "fields": [
              "title"
            ],
            "query": "the",
            "type": "phrase"
          }
        },
        {
          "multi_match": {
             "fields": [
              "title"
            ],
            "query": "Brown",
            "type": "phrase"
          }
        },
         {
          "multi_match": {
             "fields": [
              "title"
            ],
            "query": "Fox",
            "type": "phrase"
          }
        }
      ]
    }
  }
}
'

response

{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.640912,
    "hits" : [
      {
        "_index" : "dmm_native",
        "_id" : "1",
        "_score" : 0.640912,
        "_source" : {
          "title" : "Quick the Brown Fox",
          "release_date" : "2023-01-01",
          "views" : 123
        }
      }
    ]
  },
  "profile" : {
    "shards" : [
      {
        "id" : "[sH9l842iSsSMZqNmk0SNxg][dmm_native][0]",
        "node_id" : "sH9l842iSsSMZqNmk0SNxg",
        "shard_id" : 0,
        "index" : "dmm_native",
        "cluster" : "(local)",
        "searches" : [
          {
            "query" : [
              {
                "type" : "BooleanQuery",
                "description" : "+title:brown +title:fox",
                "time_in_nanos" : 3099208,
                "breakdown" : {
                  "set_min_competitive_score_count" : 0,
                  "match_count" : 0,
                  "shallow_advance_count" : 0,
                  "set_min_competitive_score" : 0,
                  "next_doc" : 6875,
                  "match" : 0,
                  "score_count" : 1,
                  "next_doc_count" : 2,
                  "compute_max_score_count" : 0,
                  "compute_max_score" : 0,
                  "advance" : 0,
                  "advance_count" : 0,
                  "score" : 4417,
                  "count_weight_count" : 0,
                  "build_scorer_count" : 2,
                  "create_weight" : 2565541,
                  "shallow_advance" : 0,
                  "count_weight" : 0,
                  "create_weight_count" : 1,
                  "build_scorer" : 522375
                },
                "children" : [
                  {
                    "type" : "TermQuery",
                    "description" : "title:brown",
                    "time_in_nanos" : 2224082,
                    "breakdown" : {
                      "set_min_competitive_score_count" : 0,
                      "match_count" : 0,
                      "shallow_advance_count" : 1,
                      "set_min_competitive_score" : 0,
                      "next_doc" : 0,
                      "match" : 0,
                      "score_count" : 1,
                      "next_doc_count" : 0,
                      "compute_max_score_count" : 0,
                      "compute_max_score" : 0,
                      "advance" : 2083,
                      "advance_count" : 2,
                      "score" : 2250,
                      "count_weight_count" : 0,
                      "build_scorer_count" : 3,
                      "create_weight" : 1929333,
                      "shallow_advance" : 3833,
                      "count_weight" : 0,
                      "create_weight_count" : 1,
                      "build_scorer" : 286583
                    }
                  },
                  {
                    "type" : "TermQuery",
                    "description" : "title:fox",
                    "time_in_nanos" : 603458,
                    "breakdown" : {
                      "set_min_competitive_score_count" : 0,
                      "match_count" : 0,
                      "shallow_advance_count" : 1,
                      "set_min_competitive_score" : 0,
                      "next_doc" : 0,
                      "match" : 0,
                      "score_count" : 1,
                      "next_doc_count" : 0,
                      "compute_max_score_count" : 0,
                      "compute_max_score" : 0,
                      "advance" : 542,
                      "advance_count" : 1,
                      "score" : 875,
                      "count_weight_count" : 0,
                      "build_scorer_count" : 3,
                      "create_weight" : 570334,
                      "shallow_advance" : 375,
                      "count_weight" : 0,
                      "create_weight_count" : 1,
                      "build_scorer" : 31332
                    }
                  }
                ]
              }
            ],
            "rewrite_time" : 119000,
            "collector" : [
              {
                "name" : "QueryPhaseCollector",
                "reason" : "search_query_phase",
                "time_in_nanos" : 23750,
                "children" : [
                  {
                    "name" : "SimpleTopScoreDocCollector",
                    "reason" : "search_top_hits",
                    "time_in_nanos" : 18125
                  }
                ]
              }
            ]
          }
        ],
        "aggregations" : [ ],
        "fetch" : {
          "type" : "fetch",
          "description" : "",
          "time_in_nanos" : 2136625,
          "breakdown" : {
            "load_stored_fields" : 1114708,
            "load_source" : 2375,
            "load_stored_fields_count" : 1,
            "next_reader_count" : 1,
            "load_source_count" : 1,
            "next_reader" : 233833
          },
          "debug" : {
            "stored_fields" : [
              "_id",
              "_routing",
              "_source"
            ]
          },
          "children" : [
            {
              "type" : "FetchFieldsPhase",
              "description" : "",
              "time_in_nanos" : 135250,
              "breakdown" : {
                "process_count" : 1,
                "process" : 31750,
                "next_reader" : 103500,
                "next_reader_count" : 1
              }
            },
            {
              "type" : "FetchSourcePhase",
              "description" : "",
              "time_in_nanos" : 10416,
              "breakdown" : {
                "process_count" : 1,
                "process" : 10208,
                "next_reader" : 208,
                "next_reader_count" : 1
              },
              "debug" : {
                "fast_path" : 1
              }
            },
            {
              "type" : "StoredFieldsPhase",
              "description" : "",
              "time_in_nanos" : 1208,
              "breakdown" : {
                "process_count" : 1,
                "process" : 792,
                "next_reader" : 416,
                "next_reader_count" : 1
              }
            }
          ]
        }
      }
    ]
  }
}

@pgomulka pgomulka added :Search/Search Search-related issues that do not fall into other categories and removed needs:triage Requires assignment of a team area label labels Jun 27, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jun 27, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@javanna javanna added :Search Relevance/Search Catch all for Search Relevance and removed :Search/Search Search-related issues that do not fall into other categories labels Jul 17, 2024
@elasticsearchmachine elasticsearchmachine added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 17, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@mayya-sharipova
Copy link
Contributor

@atsushi-matsui Thanks for filing this PR, but we still don't understand what's the issue.

For now, I will be closing this PR, until we understand what is the issue in #110080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Omit noMatchDocs in a bool query

6 participants